chris-babww
Member
Posted 8 months ago #
Hello,
I have a problem.
I have a sidebar. In this sidebar I would like to show something just when a single post is displayed.
The code I'm using is:
<?php if ( is_single() ) { ?>
<p>Show this just when a single post is displayed</p>
<?php } ?>
but it doesn't work.
When I try with:
<?php if ( is_home() ) { ?>
<p>Show this just in the home page</p>
<?php } ?>
It shows the sentence everywhere, both in home and in the single post.
What can I do? Thank you!!!
What's the full text of sidebar.php (or wherever you're placing this snippet)? You'll probably need to use Pastebin if it's long.
chris-babww
Member
Posted 8 months ago #
Can you share a link to the site? Have you tried disabling plugins to see if it's caused by a plugin? What theme are you using? (It doesn't appear to have a widget-ready sidebar, which seems odd.)
you have probably some code running before the sidebar - somewhere in the templates (could be from a plugin ?) - which modifies the original query string;
possibly try to add <?php wp_reset_query(); ?> bofore your code.
chris-babww
Member
Posted 8 months ago #
It works. I have just added <?php wp_reset_query(); ?> before the code.
If you want to have a look to the website, the url is: http://www.halcyon-hills.co.uk . The theme has been made by me and the designer of the company.
Thank you for everything!
Byeeeee!
It works. I have just added <?php wp_reset_query(); ?> before the code.
the wp_reset_query(); should be added just after your custom query in the sidebar; into line 12 of the pastebin code.
http://codex.wordpress.org/Function_Reference/query_posts#Secondary_Loops
quoted from that link:
If you must use query_posts(), make sure you call wp_reset_query() after you're done.