WordPress.org

Ready to get started?Download WordPress

Forums

Only Display Posts from Certain Categories on a Page (2 posts)

  1. Masakik
    Member
    Posted 4 years ago #

    How do you display certain category posts on a page.

    For example: I have Categories X, Y, Z. I create a page and I only want to display posts from X, and Y on that page.

    Is this possible?

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    read the corresponding chapters of the codex:
    categories:
    http://codex.wordpress.org/Template_Tags/query_posts#Category_Parameters

    and in general:
    http://codex.wordpress.org/Template_Tags/query_posts

    example:
    add this code (with the IDs of your categories instead of 2,7,9) before the begin of the loop:

    <?php global $query_string;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($query_string . "&cat=2,7,9&paged=".$paged);
    ?>

    beefore the begin of the loop:

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.