Selecting an array of Categories to display (2 posts)

  1. julesmoretti
    Posted 7 years ago #

    Might be a stupid question, but did some browsing around and did not find much on the subject.

    I want a page to load up and display let say only category 1,4,5 and 7
    And perhaps only show those on the side bar. is that possible easily?

    Thank you for your time!!!

  2. MichaelH
    Posted 7 years ago #

    You'll want to use the category__in arguments with the template tag, get_posts() to retrieve those posts.

    Something like this in your sidebar.php:

    $args = array(
      'category__in' => array(1,4,5,7),
      'showposts' => '10',
      'orderby' => 'ID',
      'order' => 'DESC'
    if ($posts) {
    foreach($posts as $post) {
    <?php the_time('m.d.y') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    <?php }

    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

Topic Closed

This topic has been closed to new replies.

About this Topic