Ken
Ken

Reputation: 279

How to display multiple categories on homepage in wordpress

http://www.getwetsailing.com/ (wordpress)

Trying to get have 2 separate categories displayed on the homepage, where "The Garmin Quatix GPS Watch" and "West Marine Sailing Gloves 3/4 Finger" are now displayed (Both are from same category).

I assume the code below is where I need to edit (from index.php), but maybe I am way off.

<div id="content" class="columns col10">
<?php
    $cat_headline=get_option('colabs_cat_headline');
    if($cat_headline=='')$cat_headline=1;
    $cat_featured=get_option('colabs_cat_featured');
    if($cat_featured=='')$cat_featured=1;
    query_posts('showposts=2&cat='.$cat_headline);
    $i=1;
    if ( have_posts() ) :
    ?>
<div class="headline columns col10">
    <?php while ( have_posts() ) : the_post(); ?>
    <div class="featured column <?php if ($i==1){?>col6<?php }else{ ?>col4<?php }?>">
        <?php 
        if ($i==1){$image_headline_width=474;$image_headline_height=318;}else{$image_headline_width=306;$image_headline_height=215;}
        colabs_image('width='.$image_headline_width.'&height='.$image_headline_height.'&play=true'); 
        $i++;
        ?>
        <h3 class="headline-title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
        <p><?php excerpt();?></p>
        <a href="<?php the_permalink();?>" class="more-link"><?php _e('Continue Reading','colabsthemes');?> &rarr;</a>
    </div><!-- .featured1 -->
    <?php endwhile; ?>

</div><!-- .headline -->
<?php endif; ?>

<?php colabs_latest_post(5,'col10');?><!-- .recent-entry -->



</div><!-- #content -->

Any help is much .

Thanks, Ken

Upvotes: 0

Views: 1882

Answers (2)

itskawsar
itskawsar

Reputation: 1242

Your are passing only one categories on your query. For that cause your query can have only post from one category. May be you need posts from $cat_headline and $cat_featured categories.

So, you should modify query_posts('showposts=2&cat='.$cat_headline); with query_posts('posts_per_page' => 2, 'category__and' => array($cat_headline, $cat_featured));

Your code will be like following:

$cat_headline=get_option('colabs_cat_headline');
if($cat_headline=='')$cat_headline=1;

$cat_featured=get_option('colabs_cat_featured');
if($cat_featured=='')$cat_featured=1;

query_posts( array('posts_per_page' => 2, 'category__and' => array($cat_headline, $cat_featured)) );

Check full documentation on wordpress codex, it can help you more.

Thanks.

Upvotes: 1

J_B
J_B

Reputation: 185

Quick answer, but... try this: Modify the query_posts() call to gather posts from your two categories, assuming you know or can find out their id's. query_posts() is what is actually doing the database retrieval.

query_posts( array( 'category__and' => array(ID_OF_FIRST_CATEGORY, ID_OF_SECOND_CATEGORY) );

Upvotes: 0

Related Questions