Support » Themes and Templates » Display one category in a mini-loop

  • Resolved icanlevitate

    (@icanlevitate)


    I am currently building a site for a church and I want on the main page to have a feed for services and a feed for events and display those both in separate feeds on the same page.

    I know I can exclude categories from the loop and display them that way with something like this:

    <?php if (in_category('1')) continue; ?>

    But if the site grows to include more categories, it requires me updating that to cover the numbers of all categories it should exclude.

    Is there a way to have it only display one instead of exclude one?

Viewing 3 replies - 1 through 3 (of 3 total)
  • this topic says resolved, but here is the code i use to display 5 posts with dates in a bulleted list. just change the category and number of posts in line 1,


    <?php $posts = get_posts( "category=2&numberposts=5" ); ?>
    <?php if( $posts ) : ?>
    <ul>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <li>
    <span class="date">
    <?php the_time('F j'); ?>
    </span>
    <a href=<?php the_permalink() ?>>
    <?php the_title(); ?>
    </a>
    </li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>

    This code isn’t working – I’m getting all kinds of errors…
    I know there’s an extra > in there, but it’s giving me issues with <?php foreach( $posts as $post ) : setup_postdata( $post ); ?> too.

    I know there’s extra spaces, but I don’t know where… I wish people would just use the “code” feature and post the code properly and completely… *sigh*

    Anyone help?

    Edit: What I’m really looking to do here is display titles/links to the posts in one specific category on a page (along with other content). Short of making a page template for a cat archive I can’t figure this one out. Linking to the cat archive alone won’t work, because I need to have other content on this page…

    the above code is working for me in WP2.3 …so far.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display one category in a mini-loop’ is closed to new replies.