• Hi, I am using the following code in a page template to show a particular category on a page. I would like to add a second category to this page template, so that posts from both will display on the page. How would I do so?

    <?php
    // page id 364 video & audio will get category ID 39 video posts and 52 audio posts
    if (is_page('364') ) {
    $cat = array(39);
    }
    
    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
       'category__in' => $cat,
       'showposts' => $showposts,
       'caller_get_posts' => $do_not_show_stickies
       );
    $my_query = new WP_Query($args); 
    
    ?>
    
    	<?php if( $my_query->have_posts() ) : ?>
    
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<?php
    			//necessary to show the tags
    			global $wp_query;
    			$wp_query->in_the_loop = true;
    			?>

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Ken Soszka

    (@ksoszka)

    Clarification: the comment there is what I want the code to do, there is no reference to category 52 audio posts in the code – that’s what I need.

    // page id 364 video & audio will get category ID 39 video posts and 52 audio posts

    Thread Starter Ken Soszka

    (@ksoszka)

    Hi, anybody around that might help me with this? Thanks!

    Might be easier to use a new wp_query. This will show the latest post from mycategory; change showposts to another number or -1 to show all, and can be used mutliple times on a page, and works inside the original WP loop. Wrap it in a if statement if you only want it to show on that particular page 364.

    <?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
    <?php the_title(); ?></a><br /><?php the_content(); ?><?php endwhile; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display two particular categories on one page’ is closed to new replies.