Support » Fixing WordPress » Show a specific category on homepage

  • Resolved syber90

    (@syber90)



    this is the code that I have in my index.php file;

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

    what should I add to it so I can show on my homepage only posts from category id=3, for example ?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • MichaelH

    (@michaelh)

    Might look at using Custom Query String Reloaded for that.

    Also, The Loop article discusses excluding posts of a certain category so just change that to exclude all but category 3.

    syber90

    (@syber90)

    That might be a solution but it won’t work for me because I won’t be able to order the posts from that specific category the way I want on the homepage.

    That’s why I need to show only category 3 on the homepage and with the help of AStickyPostOrderER plugin I will be able to order them how I want.

    So, I’m looking for a function to display the category 3 on the homepage and not posts from category 3.

    Any help would be appreciated.

    syber90

    (@syber90)

    Done it!

    Here’s the code I used:

    <?php
       if (is_home()) {
          query_posts("cat=3");
       }
    ?>

    It should be placed before the Loop.

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

    syber90

    (@syber90)

    here’s another hack to show what category you want on homepage

    <?php if (have_posts()) :query_posts($query_string .'&cat=3'); while (have_posts()) : the_post(); ?>

    And if you want to exclude a specific category from homepage, instead of '&cat=3', put '&cat=-3' .

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show a specific category on homepage’ is closed to new replies.