Forums

[resolved] Show Posts from Two Specific Categories Figured out but how about number of post (3 posts)

  1. arcab4
    Member
    Posted 4 years ago #

    So i used this code to show posts from two specific categories:

    <?php query_posts(array('category__and'=>array(3,46))); ?>
    <?php while (have_posts()) : the_post(); ?>
    <span class="listings"><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?>"><?php the_title('','','&raquo;'); ?></a></span> <?php the_excerpt('Read the rest of this entry &raquo;') ?><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?>">Click Here To Continue</a>&nbsp;<br>&nbsp;<br>
    <?php endwhile;?>

    So this outputs all the posts that match only categories 3 and 46. But the problem is it shows ALL posts that match that.

    Question 1: how do i show only maybe the 3 most recent post? i know it was showposts=3 but b/c of the array coding, i don't know where to put it.

    Thank you,

  2. arcab4
    Member
    Posted 4 years ago #

    just for anyone ever looking...i think i figured it out.

    this will show posts that are ONLY in category 3 and 46 and then show only 3 posts from it (instead of all the posts)

    <? $count = 0 ; ?>
    <?php query_posts(array('category__and'=>array(3,46))); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?if ($count<3) {?>
    <span class="listings"><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?>"><?php the_title('','','&raquo;'); ?></a></span> <?php the_excerpt('Read the rest of this entry &raquo;') ?><a href="<?php the_permalink(); ?>" title="Permanent link to <?php the_title(); ?>">Click Here To Continue</a>&nbsp;<br>&nbsp;<br>
    <? } ?>
    <? $count ++;?>
    <?php endwhile;?>
  3. coppertopjsq
    Member
    Posted 4 years ago #

    Hello. I was wondering if you could help me with something similar. I would like to make the drop down category widget (wp 2.3.3) to show only posts in two distinct categories. I want to set one and allow the user to choose the other. Do you have any idea how I can do this?

    I looked at the code in widgets.php and tried to do something similar to what you had cat=3,4 or something like that but it didn't work.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic