WordPress.org

Forums

How to set a default category (4 posts)

  1. cigumigu
    Member
    Posted 6 years ago #

    Hello everybody

    I want to know how to make my site open on a specific category. Is that possible?

    Thanks in advance

  2. stvwlf
    Member
    Posted 6 years ago #

    modify your /wp-content/themes/{themename}/index.php template file
    add this

    <?php if (is_front_page()) { query_posts("cat=6"); } ?>

    before the WP loop, which generally starts with

    <?php if ( have_posts() ) :
             while ( have_posts() ) : the_post(); ?>

    change cat=6 to the cat ID of the cat you want the site to open to. You find the cat ID by going to the cat maint screen - point at the name of the cat - look n the lower left corner of browser window on status line - you will see a URL - that cat ID is at the end of the URL

    That should do it

  3. MichaelH
    Member
    Posted 6 years ago #

    As an example, using the WordPress Default theme, you would edit the wp-content/themes/default/index.php file and change this:

    <?php if (have_posts()) : ?>

    to this:

    <?php
    if (is_home()) {
    $mycat = 7; //put your category id in place of the 7
    query_posts($query_string . '&cat=' . $mycat);
    }
    ?>
    <?php if (have_posts()) : ?>

    oops see stvwlf got there first ;)

  4. TapeBoy929
    Member
    Posted 6 years ago #

    We can add a line of code that qualifies the post before displaying it. Open up the page at wp-content/themes/THEME_NAME/index.php. If we want category 3 to be our default, change

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    to

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if (in_category('3') && is_home() ) continue; ?>

    If the category for each post to be displayed is not 3, it will break to the next post. Have fun.

    [signature moderated Please read the Forum Rules]

Topic Closed

This topic has been closed to new replies.

About this Topic