Hi
By googling and reading I got a code to have the last post in a row-column by itself, and the others in following rows and columns.
Problem is I can’t seem to be able to add custom class to the last post (first row), and avoid a unnecessary class there (though this is really minor and irrelevant). Also the thumbnial is not showing.
What I have
<div class="row fz-v-spacer">
<?php while( have_posts() ): the_post();
if($i==0): $column_xs = 12; $column_sm = 12; $class = '';
elseif($i > 0 && $i <= 2): $column_xs = 12; $column_sm = 6; $class = ' second-row-padding';
elseif($i > 2): $column = 4; $class = ' third-row-padding';
endif;
?>
<div class="col-xs-<?php echo $column_xs; ?> col-sm-<?php echo $column_sm; echo $class; ?> fz-blog-post-wrap">
<?php
// Check if the post has a Post Thumbnail assigned to it, if yes show it, and add class, alt, and title to it
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'thumbnail', array(
'alt' => trim(strip_tags( $post->post_title )),
'title' => trim(strip_tags( $post->post_title )),
'class' => 'img-responsive fz-thumb-img',
));
}
?>
<div class="fz-blog-post">
<?php the_title( sprintf('<h1 class="fz-post-title"><a href="%s">', esc_url( get_permalink() ) ),'</a></h1>' ); ?>
<?php the_excerpt(); ?>
</div>
</div>
<?php $i++; endwhile; ?>
</div>
What I would like to have, with a limit of 9 posts per page (including the latest one) in case of 2 posts per row (like the below sample), or 10 posts limit in case of 3 posts per row (<div class="col-xs-12 col-sm-4">
)
<div class="row fz-hv-padding-9">
<div class="col-xs-12">
Last post
</div>
</div>
<div class="row fz-hv-padding-9">
<div class="col-xs-12 col-sm-6">
Other post
</div>
<div class="col-xs-12 col-sm-6">
Other post
</div>
</div>
The above to be structured like this for the latest post, and the other ones.
The latest in the full width div
<div class="row fz-hv-padding-9">
<div class="col-xs-12 col-sm-3">
Thumbnail
</div>
<div class="col-xs-12 col-sm-9">
<h2 class="fz-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</div>
</div>
The other posts in the half/third width div
<div class="row fz-hv-padding-9">
<div class="col-xs-12">
Thumbnail
</div>
<div class="col-xs-12">
<h2 class="fz-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</div>
</div>
I tried different codes (rearranged/created by myself - not a coder), and results were always blank page, if you want to see my efforts I can post it, but it’d be a waste.
Kinda OT, but which of these two are better, or they are just different ways of doing the same?
<h2 class="fz-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_title( sprintf('<h1 class="fz-post-title"><a href="%s">', esc_url( get_permalink() ) ),'</a></h1>' ); ?>