In my loop, I'm trying to set it so that certain text is displayed on certain pages, if there are no posts to display.
I thought this would be simple, using is_post()
, but it seems that this function does not work when you are in The Loop.
Does any body know how I can identify the page that is currently being shown, whilst in The Loop?
The below code is from loop.php
- it's how I have the code structured, as the content is not important in this instance. However, for those interested, here is my full page.php
and loop.php
code - http://pastebin.com/hDjR6C7A.
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<!-- Do stuff here -->
<?php endwhile; ?>
<?php else : ?>
<?php if(is_page(162)) : // Careers ?>
<!-- Do stuff here -->
<?php if(is_page(716)) : // Partnerships ?>
<!-- Do stuff here -->
<?php elseif(is_search()) : ?>
<!-- Do stuff here -->
<?php endif; ?>
<?php endif; ?>
endwhile
in your code.loop.php
file. The Loop is used by various templates to display posts, and in the case of two pages, and the search, I need to show some text if there are not matching posts. I've updated with a link to Pastebin that contains my full code forpage.php
andloop.php
. Thanks.