sidebar code working on index but not on single template
-
Hello,
I am trying to get a list of posts from a certain category to display in my sidebar. I have followed all of the previous discussions and the examples in the codex. It works great on my index page, but when i go to a single entry the sidebar suddenly doesn’t list them. For testing purposes I have made my single.php have exactly the same code as my index.php. Any ideas why it would work in one and not the other?
currently it is a loop within a loop. perhaps this is not necessary.here are the various codes i’ve tried in my sidebar, both work on the index page, but not on the single.php:
1.
‘<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php query_posts(‘category_name=projects&showposts=27’); ?>
<?php while (have_posts()) : the_post(); ?>
“><?php the_title(); echo “
“; ?>
<?php endwhile;?>
<?php endwhile; else: ?>
sorry, no projects entered yet.
<?php endif; ?>’
2.
‘<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php if ( in_category(‘2’) ) { ?>
“><?php the_title(); echo “
“; ?>
<?php } else { ?>
echo “tart”
<?php } ?>
<?php endif; ?>’
- The topic ‘sidebar code working on index but not on single template’ is closed to new replies.