Blog.php template: How to call for if/else statement
-
I have created a site using WordPress where I didn’t want the blog to be the home page. Instead, I wanted it to be https://sitename.com/blog/ – which I’ve successfully done.
What I’ve done is I’ve created a blog.php page and made it a template using:
<?php /* Template Name: Blog */ ?>
I then created a WordPress Page and selected the ‘Blog’ template from the right hand side of the page. This successfully linked the template to the permalink (https://sitename.com/blog/) and so now I have my index.php as my home page and my blog.php acting as my Blog home page.
Now, to explain the problem…
I’m trying to create an if/else statement that will display a particular image based upon what the page is.
Here’s the if/else statement I have so far:
<?php if (is_page('attorneys') ) { ?> <img src="<?php echo get_stylesheet_directory_uri() ?>/images/railing.jpg"> <?php } elseif (is_page_template('blog.php') { ?> <img src="<?php echo get_stylesheet_directory_uri() ?>/images/sunset.jpg"> <?php } ?>
I’ve tried to call the blog template in numerous ways, including:
is_page(‘114’), is_page(114), is_page(‘blog’), is_page_template(‘blog.php’) … but none of these seem to work!I’ve messed around a little bit with is_front_page and is_home, but these aren’t really working either…and I’ve played around with the Settings > Reading – Front Page and Home Page, and that doesn’t work either.
Can anyone help? How do I correctly call the blog template page so it will display the correct image?
- The topic ‘Blog.php template: How to call for if/else statement’ is closed to new replies.