WordPress.org

Support

Support » How-To and Troubleshooting » How to set a default category

How to set a default category

  • Hello everybody

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

    Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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

    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 😉

    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]

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to set a default category’ is closed to new replies.