Forums

Queries in left sidebar? (3 posts)

  1. marros166
    Member
    Posted 2 weeks ago #

    I am trying to have a list in my left sidebar that will show the previous ten posts and, ideally, display the tag next to the link if the post has one of three specific tags. At this point, though, I'd just be happy getting it to display the name of the first tag. (I figured it would be a good starting place)

    So I put the following into my sidebar

    <?php query_posts('showposts=10'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title() ?></a>
    <?php $category = get_the_category();
    echo $category[0]->cat_name;?></li>

    That works, but unfortunately it seems to break the rest of my blog. When that code is present in my sidebar, all other pages (posts, single pages, etc.) just display the contents of my index.

    I've read through the codex and tried using the multiple loop suggestions, but I can't get anything to work.

  2. vachi
    Member
    Posted 2 weeks ago #

    i am kinda noob but don;t you need a <?php endif; ?> after the post display

  3. marros166
    Member
    Posted 2 weeks ago #

    Oh yeah sorry, I have that, but I left it out of my post. After that I have:

    <?php endwhile; endif; ?>

Reply

You must log in to post.

About this Topic