<?php
// get threee posts, display content for first, excerpt fot the other two
$count = 0;
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 3,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
$count++;
if ( $count < 2 ) {
the_content('Read the rest of this entry »');
} else {
the_excerpt();
}
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
<?php
//get all categories and display two posts from each category
$taxonomy = 'category';
$param_type = 'category__in';
$term_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
foreach( $terms as $term ) {
$args=array(
"$param_type" => array($term->term_id),
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 2,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
$count = 0;
echo 'List of Posts in '.$taxonomy .' '.$term->name;
while ($my_query->have_posts()) : $my_query->the_post();
$count++;
if ( $count < 2 ) { ?>
<!---handle column 1 here --->
<?php
} else { ?>
<!---handle column 2 here --->
<?php
}
?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
}
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
That’s amazing thank you very much! One other question using this the navlink which takes you to the next page will display the next page which is exactly the same as the first. Can you make the above code conditional for the front page only and then every page after that would just be the category columns with posts ordered by date?
One more question. If I wanted to show a selection of categories instead of all of them would I just add to the $args=array(
‘include’ => 1,2,etc..?
Can you make the above code conditional for the front page
Wrap that first loop in a Conditional Tag such as
<?php
// get threee posts, display content for first, excerpt for the other two
if (is_home()) {
$count = 0;
///first loop here
wp_reset_query(); // Restore global post data stomped by the_post().
}
?>
If I wanted to show a selection of categories
$term_args=array(
'orderby' => 'name',
'order' => 'ASC',
'include' => '71,22,3'
);
Are you a volunteer or do you get paid for this awesome help. I ended up using the following code to just show my layout on the front page:
<?php
// create first page content
$paged = get_query_var(‘paged’);
if ($paged < 2): ?>
Huge thanks for the second code I couldn’t get it to work for the life of me today. You cleared up a huge headache.
Except for automattic.com employess, the rest of us are volunteers.
Good luck. Will mark this resolved.
Greetings Guys,
Foremost, allow me to thank Kevin_Curry for the straight forward question, and also to thank MichaelH for the code and explanation.
I’ve been caught up in a similar bind { trying to implement a custom front page layout : Carousel/ Slideshow from Category 1, then a 3-Col Horizontal Sequence of posts { limited to either 3, or 6 }, from a second category.
MichaelH’s code works perfect { pulling posts from all categories, and sequencing posts into two columns }. How can this code be adapted for use in the 3 column setup described above?
Cheers
Q