• After scouring the forum…

    I have been able to show only two categories on the home page and limit it to a maximum of only 4 posts in total but I cannot for the life of me work out/find out how to show 2 posts from each of the two categories.

    Anyone?

    Here is what I have so far…

    if (is_home()) {
    query_posts($query_string . "&cat=7,8&posts_per_page=4");
    }

    This code is on home.php.

    Thanks in advance

Viewing 1 replies (of 1 total)
  • Thread Starter [email protected]

    (@danfillimcom)

    Figured it out but would like to know if it is right way to go about it… Anyone got any feedback? I have also added link to titles and individual posts which seemed very ass about. I am sure there is a cleaner way to do it all?

    <div id="newshome">
    	<?php
        // Get the ID of a given category
        $category_id = get_cat_ID( 'news' );
    
        // Get the URL of this category
        $category_link = get_category_link( $category_id );
    ?>
    	<h2><a href="<?php echo esc_url( $category_link ); ?>">WAYS <?php echo get_the_category_by_id(6); ?></a></h2>
    <?php query_posts('category_name=news&showposts=3'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post();
    		if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    
    <a href="<?php the_permalink() ?>"><h3><?php the_title(); ?></h3></a>
    <?php the_content() ?>
    
    <?php endwhile; ?>
    <?php endif; ?>
    </div>
    
    <div id="eventshome">
    	<?php
        // Get the ID of a given category
        $category_id = get_cat_ID( 'events' );
    
        // Get the URL of this category
        $category_link = get_category_link( $category_id );
    ?>
    	<h2><a href="<?php echo esc_url( $category_link ); ?>">WAYS <?php echo get_the_category_by_id(7); ?></h2></a></h2>
    <?php query_posts('category_name=events&showposts=3'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post();
    		if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    
    <a href="<?php the_permalink() ?>"><h3><?php the_title(); ?></h3></a>
    <?php the_content() ?>
    
    <?php endwhile; ?>
    <?php endif; ?>
    </div>
Viewing 1 replies (of 1 total)
  • The topic ‘show 2 categories on home page with two posts for each category’ is closed to new replies.