• 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.

    Cheers.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you post what you have tried?

    Thread Starter rennanslt

    (@rennanslt)

    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]

    with the loop showing only one category

    http://codex.wordpress.org/Function_Reference/query_posts

    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 ); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘The loop with only one cathegory’ is closed to new replies.