• Resolved thomasareed

    (@thomasareed)


    I’m working on a theme, and need to do something rather unusual on the front page. I want to display a row of three boxes, side-by-side (think 1×3 table). In each box, I want to display the featured image and a short excerpt of posts in a particular category, and I want that entire block of three pages to cycle through all the posts in that category. I can do the cycling easily with jQuery, but what I’m not sure how to do is get the elements I want from WordPress. How do I put code in the front-page.php file in my theme that will cycle through all posts in a category and load the featured image and excerpt from each?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • I use Display-Posts-Shortcode plugin and wrap the excert in html

    Thread Starter thomasareed

    (@thomasareed)

    Thanks for the response, but yesterday I finally managed to work out a solution on my own. I simply did this:

    <?php
    $args= array(
    	'category_name' => 'front-page',
    	'posts_per_page' => -1,
    	'orderby' => 'date',
    	'order' => 'ASC'
    );
    $the_query = new WP_Query( $args );
    $numBoxes = 0;
    $boxGroup = 1;
    
    // The Loop
    while ( $the_query->have_posts() ) {
    	$the_query->the_post();
    	if ($boxGroup > 1)
    		$hideStyle = 'style="display: none;" ';
    	else
    		$hideStyle = '';
    	if ($numBoxes == 0)
    		echo '<div '.$hideStyle.'class="frontBoxGroup" id="frontBoxGroup-'.$boxGroup.'">';
    	echo '<div class="frontBoxContent">';
    	the_content();
    	echo '</div>';
    	$numBoxes++;
    	if ($numBoxes >= 3) {
    		echo '</div>'."\r";
    		$numBoxes = 0;
    		$boxGroup++;
    	}
    }
    if ($numBoxes < 3)
    	echo '</div>'."\r";
    ?>

    After that block of code, you just have to do:

    <?php wp_reset_query(); ?>

    Then proceed with the code to display the content of the page.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display multiple post excerpts on a page’ is closed to new replies.