I want to use If, If else and else on wordpress homepage, i am using following condition
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
}?>
<?php if else {
<img src="<?php echo catch_that_image() ?>" width="64" height="64" alt="<?php the_title(); ?>" />
} else {
<img src="http://www.technoarea.in/wp-content/themes/TA/images/TA_Logo.png" width="64" height="64" alt="<?php the_title(); ?>" />}
?>
<?php ?>
I want to show thumbnail first on homepage, if thumbnail is not available then it must use first image from post as thumbnail and if there is no image in post then it use this image
http://www.technoarea.in/wp-content/themes/TA/images/TA_Logo.png
can you please tell me where i am wrong because the above code is not working
An alternative would be:
<?php if ($condition) : ?>
<p> Some html code </p> <!-- or -->
<?php echo "some php code"; ?>
<?php else : ?>
<p> Some html code </p> <!-- or -->
<?php echo "some php code"; ?>
<?php endif; ?>
the syntax for php is as follows:
<?php
if(statement that must be true)
{
(code to be executed when the "if" statement is true);
}
else
{
(code to be executed when the "if" statement is not true);
}
?>
You only need the opening and closing php tags (<?php ... ?>) once; one before your php code and the other after. You also need to use "echo" or "print" statements. These tell your program to output the html code that will be read by your browser. The syntax for echo is as follows:
echo "<img src='some image' alt='alt' />";
which will output the following html:
<img src='some image' alt='alt' />
You should get a book about php. www.php.net is also a very good resource. Here are links to the manual pages about if, echo, and print statements:
http://us.php.net/manual/en/control-structures.if.php
http://us.php.net/manual/en/function.echo.php
http://us.php.net/manual/en/function.print.php
edit: You can also use "elseif" to give a new condition that must be met for the next section of code. For example:
<?php
if(condition 1)
{
(code to be executed if condition 1 is true);
}
elseif(condition 2)
{
(code to be executed if condition 1 is false and condition 2 is true);
}
else
{
(code to be executed if neither condition is true);
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With