• Resolved iacovibus

    (@iacovibus)


    Kudos for the great theme, it really deserves the name it was given.

    I have question regarding the loop on the homepage. I’ve set “Latest post” on the Front Page, and this way I’m getting all new posts there. But, I’d like to have only posts that belong to a certain category (let’s say a category with an id of 4) on the Front Page. Tried to change the loop, but not sure I’m doing it right.

    Should I change something in index.php (this part maybe?)

    <?php if ( have_posts() && !is_404() ) : ?>
                                <?php while ( have_posts() ) : ?>
                                    <?php the_post(); ?>
                                    <article <?php tc__f('__article_selectors') ?>>
                                        <?php
                                            do_action( '__loop' );
                                        ?>
                                    </article>
                                <?php endwhile; ?>

    or somewhere else? Thanks in advance and keep up the great work!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Theme Author presscustomizr

    (@nikeo)

    Thread Starter iacovibus

    (@iacovibus)

    Hey Nicolas,

    Thanks, it really helped. So, just in case someone else would like to show posts from specific categories only, this would be the code that needs to be replaced in index.php.

    <?php if ( have_posts() && !is_404() && !is_home() ) : ?>
                                <?php while ( have_posts() ) : ?>
                                    <?php the_post(); ?>
                                    <article <?php tc__f('__article_selectors') ?>>
                                        <?php
                                            do_action( '__loop' );
                                        ?>
                                    </article>
                                <?php endwhile; ?>
    
                            <?php endif; ##end if have posts ?>
    
                            <?php if ( is_home() ) : ?>
                                <?php   $wp_query;
                                        $categoryvariable = 4;
                                        $args = 'cat=' . $categoryvariable . '&orderby=date&order=ASC';
                                        query_posts( $args );
                                ?>
                                <?php while ( have_posts() ) : ?>
                                    <?php the_post(); ?>
                                    <article <?php tc__f('__article_selectors') ?>>
                                        <?php
                                            do_action( '__loop' );
                                        ?>
                                    </article>
                                <?php endwhile; ?>
    
                            <?php endif; ##end if have posts ?>

    Note that in this case, I want to show only posts with category id of 4 on the front page:

    $categoryvariable = 4;

    Theme Author presscustomizr

    (@nikeo)

    Thanks for sharing this code @iacovibus!

    Yes. Thank you @iacovibus!

    and @nikeo for the tip on query_posts.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom category parameter in loop for homepage’ is closed to new replies.