• Hi I need your help. I’m using WordPress as a CMS and blog tool and have succesfully manipulated the templates so that pages appear in one of three different menus depending on their position within a heirarchy. This works really well but now I want to do something very simple and am struggling. I want to list all the blog posts in a specific category on a specific page. All I need is the bit of code that says “display blogs within this category id”. I want to show the posts as if they were displayed in a category page. Once this is done I can then either use specific page templates or a custom field to define which category each page displays. I DO NOT WANT TO USE CATEGORY PAGES OR BRING THE CATEGORY ID IN THROUGH THE URL. Please help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter adrobinson

    (@adrobinson)

    Thread Starter adrobinson

    (@adrobinson)

    Sorted – I’m using a Custom Field in each page called “CategoryNumber” and a value of category=3 or category=2 etc.

    In the code I use:

    <?php $key=”CategoryNumber”; $param = get_post_meta($post->ID, $key, true); $posts = get_posts( $param ); ?>

    Thread Starter adrobinson

    (@adrobinson)

    if you didnt want to type category=3 etc in each piece of meta data, you could jsut enter a number like “3” and then use the param like $posts = get_posts(“category=$param”)

    ENDS

    For each template, you can use the query_posts() function (before the loop) and exclude all but the intended category.

    Then just run a WordPress Loop and display the posts how you want. You can probably model the loop after your page.php, just add the query_posts().

    This also prevents you from having to create that custom field for all your posts.

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

The topic ‘Pages display specific categories’ is closed to new replies.