For the left side you could do this,
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 10,
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
);
$loop = new WP_Query( $args );
// add custom function before loop, so you can apply excerpt filter only to this case
do_action('my_custom_pre_loop_action');
// is url parameter set, if so force it to integer
$current_post_id = ! empty( $_GET['postid'] ) ? absint($_GET['postid']) : 0;
while ( $loop->have_posts() ) : $loop->the_post();
$post_class = 'et_blog_post';
// is the current loop item the same as the post in view?
if ( get_the_id() === $current_post_id ) {
$post_class .= ' active';
} else if ( 0 === $loop->current_post ) {
$post_class .= ' active' // make first post active as a fallback
}
?>
<article id="post-<?php the_ID(); ?>" class="<?php echo $post_class ?>">
<div class="entry-content">
<h3 class="entry-title">
<a href="/blog/?postid=<?php the_ID(); ?>#post">
<?php the_title(); ?>
</a>
</h3>
<div class="post-content">
<div class="post-content-inner">
<?php the_excerpt(); ?>
</div>
<p>
<a href="/blog/?postid=<?php the_ID(); ?>#post" class="blog-read-more">READ MORE</a>
</p>
</div>
</div>
</article>
<?php
endwhile;
// reset global $post after custom WP_Query loop
wp_reset_postdata();
And instead of setting the excerpt length with substr()
, you can use excerpt_length
filter. In the example above I added custom action which adds the length filter so that it happens only in this context and not site wide.
// apply custom exerpt lenght only when your custom action is fired
add_action('my_custom_pre_loop_action', 'apply_my_custom_exerpt_length');
function apply_my_custom_exerpt_length() {
// if you want to apply this globally on your site then just move the add_filter to your functions.php
add_filter('excerpt_length', 'my_custom_exerpt_length');
}
function my_custom_exerpt_length($length) {
return 100;
}
And for completeness sake, example for the right side,
<?php
$current_post_id = ! empty( $_GET['postid'] ) ? absint($_GET['postid']) : 0;
$post = get_post( $current_post_id );
?>
<div class="entry-content">
<?php if ( $post ) : ?>
<h1><?php echo get_the_title($post); ?></h1>
<?php echo apply_filters( 'the_content', get_the_content($post) ); ?>
<?php endif; ?>
</div>