WordPress.org

Ready to get started?Download WordPress

Forums

The loop with only one cathegory (4 posts)

  1. rennanslt
    Member
    Posted 1 year 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.

    Cheers.

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    Can you post what you have tried?

  3. rennanslt
    Member
    Posted 1 year 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. alchymyth
    Forum Moderator
    Posted 1 year ago #

    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 ); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags