SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Best way to display posts from 3 different categories in one page

    I'm wondering the best way to do this. I created a custom post and the custom post can have multiple categories. I have created a custom template and I'm wondering now the best way to go about getting the posts in. I don't really understand the while loop e.g.
    PHP Code:
    <?php while ( have_posts() ) : the_post(); ?>
    , what posts is it on about? Can I give it those details, or is it better just to do:


    PHP Code:
    $posts get_posts(array( 
                
    'numberposts'   => 5,
                   
    'orderby'       => 'post_date',
                   
    'order'         => 'DESC',
                   
    'post_type'       => 'give',
                   
    'post_status'     => 'publish' 
    Wordpress absolute newbie by the way!

  2. #2
    SitePoint Member
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think It won't work for displaying 3 categories from three pages on a single page. I think you need to fetch details from all those 3 pages and join then using joins and then you can display on single page.

  3. #3
    SitePoint Zealot w1nk5's Avatar
    Join Date
    Aug 2009
    Location
    Ontario, Canada
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use the query_posts() function to change the loop; and use the 'category__and' parameter to specify which categories you want to include.

    Simply assign an array of the category ID's you want to include to 'catergory__and' and you're ready to rock.

    PHP Code:
    <?php query_posts( array( 'category__and' => array(1,3)); ?>

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

            Your content here.
                
    <?php endwhile; endif;?>


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •