As per you described, What I have got is you want to add class active
to last published post by the user.
By seeing your output
and HTML
, It seems that active
class is missing.
So to achieve that, we will add one dummy condition that will print class="active"
. I would also suggest that modify your $arg
and make in DESC
order to get last published post first.
Your final code will be something like this :
<div class="humour">
<h1 class="section_heading"> HUMOUR ON INDIAN INVESTMENT </h1>
<dl>
<?php
$args = array(
'post_type' => 'humour',
'order' => 'DESC' //Add order to get post in DESC order
);
$humour_query = new WP_Query($args);
$i=0; //Take variable and assign it 0
if ($humour_query->have_posts()) : while($humour_query->have_posts()) : $humour_query->the_post();
?>
<?php
if($i==0): //This condition will be true only once as I have added increament at the end
echo "<dt id='post-".the_ID()."' class="active">";
else:
?>
<dt id="post-<?php the_ID(); ?>">
endif;
<h1 class="link_heading"><?php the_title(); ?></h1>
<div>
<img src="https://wordpress.stackexchange.com/questions/173215/<?php print IMAGES; ?>/arrowdown.png" class="arrow" id="down"/>
<img src="<?php print IMAGES; ?>/arrowup.png" class="arrow" id="up"/>
</div>
</dt>
<dd>
<p>
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,25);
?>
</p>
</dd>
<?php
$i++; //Incremented that variable so class wont be added from second post
endwhile;
endif; ?>
</dl>
</div>
NOTE: I have assumed that accordion is working with class active
.