Forum Moderators: coopster

Message Too Old, No Replies

Multiple if statements with else statement

I can't figure out how to make it work...

         

braiiins

7:57 pm on Oct 27, 2008 (gmt 0)

10+ Year Member



I'm using WordPress. What I want to do is have the first post, on the homepage only, load the full post. Every other post should load the excerpt only, with a thumbnail of the image in the post (this is handled by a plugin, the code for that is in the div tags). Here is the code, which is probably entirely wrong since I have no idea how to go about this... don't make fun of me!:


<?php if ($loopcounter == 1 and is_home()) : ?>
<?php the_content(); ?>
<?php else : ?>
<div class="articleimagediv">
<?php if (function_exists('the_thumb')) { the_thumb('altappend=first_&width=100&height=100&category=1&offset=0&limit=1&myclassimg=articleimage&link=p'); } ?>
</div>
<?php the_excerpt() ?>
<?php endif; ?>

That is causing parse errors. How would I make it work?

andrewsmd

8:49 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this first of all
<?php
if ($loopcounter == 1 and is_home()){
the_content();
}//if
elseif{
echo("<div class='articleimagediv'>");
}//else

elseif(function_exists('the_thumb')) {
the_thumb('altappend=first_&width=100&height=100&category=1&offset=0&limit=1&myclassimg=articleimage&link=p');
}//elseif
echo("</div>");
the_excerpt();
?>
It's not really clear on what you want to do. Can you give some pseudo code on your if statements?

braiiins

12:46 am on Oct 28, 2008 (gmt 0)

10+ Year Member



Yeah, your code gave me parse errors, too.

I'm not sure about how to do pseudocode... hope this makes sense

IF is first post and is home page
- display the content

ELSE
- <div class='articleimagediv'>
- display thumbnail created by plugin
- </div>
- display the excerpt

ENDIF

We can remove the if for is_home, if necessary

[edited by: braiiins at 12:53 am (utc) on Oct. 28, 2008]

cameraman

12:49 am on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:
<?php if ($loopcounter == 1 and is_home())
the_content();
else {
?>
<div class="articleimagediv">
<?php
if (function_exists('the_thumb')) {
the_thumb('altappend=first_&width=100&height=100&category=1&offset=0&limit=1&myclassimg=articleimage&link=p');
} // EndIf have the_thumb()
?>
</div>
<?php
the_excerpt();
} // EndElse do excerpt
?>

braiiins

1:14 am on Oct 28, 2008 (gmt 0)

10+ Year Member



So I figured out the problem. I was replacing the wrong code in my template with the statements. It turns out my code worked without the first 3 lines in a different spot in the template.

Thanks guys, and sorry for wasting your time!