The loop with only one cathegory (4 posts)

  1. rennanslt
    Posted 3 years ago #

    Hello Guys.

    One trouble: I need to modify a theme, with the loop showing only one category. How can I do it? I tried to put an if inside the_loop, with the is_category (codex), but it's not working =(.

    Thank you all.


  2. Andrew
    Bawk bawk moderator
    Posted 3 years ago #

    Can you post what you have tried?

  3. rennanslt
    Posted 3 years ago #

    Well, this is the_loop on my index.php:

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
    	<?php if (in_category('News')): ?>
    	<?php get_template_part( 'content', get_post_format() ); ?>
    	<?php endif; ?>
    <?php endwhile; ?>
    <?php twentyeleven_content_nav( 'nav-below' ); ?>
    <?php else : ?>

    The result: It shows only the posts that are categorized...

    [no bumping please]

  4. Michael
    Part-Time Forum Moderator
    Posted 3 years ago #

    with the loop showing only one category


    if this is for the index page, you could try:

    <?php global $wp_query;
    $args = array_merge( $wp_query->query, array( 'category_name' => 'news' ) );
    query_posts( $args ); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic