[英]WordPress add a class for newest posts
Does sombody know how i can add a class to the newest posts in WordPress.有人知道我如何在 WordPress 的最新帖子中添加一个类。 And what i mean with the newest is the lasts posts that are added in the last minut?
我对最新的意思是最后一分钟添加的最后一个帖子?
My code now:我现在的代码:
<?php
// query
$the_query = new WP_Query(array(
'post_type' => 'post',
'category_name' => 'profiel',
'posts_per_page' => 48,
'paged' => $paged,
'meta_key' => 'online',
'orderby' => 'meta_value_num',
'order' => 'DESC'
));
if ( $the_query->have_posts() ) : ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div id="post-<?php echo $post->ID; ?>" class="profiel">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
<?php endwhile; ?>
<?php else : ?>
<div class="404 not-found">
<h3>Not Found</h3>
<div class="post-excerpt">
<p>Sorry, but there are no more posts here... Please try going back to the <a href="<?php echo remove_query_arg( 'pg' ); ?>">main page</a></p>
</div>
</div>
<?php endif;
wp_reset_query();
the_posts_pagination( array(
'mid_size' => 10
) );
?>
Get the current time, remove 60 seconds compare that to the timestamp of your post.获取当前时间,将 60 秒与帖子的时间戳进行比较。 If your post timestamp is greater than the timestamp from a minute ago then it's new.
如果您的帖子时间戳大于一分钟前的时间戳,那么它是新的。
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div id="post-<?php echo $post->ID; ?>" class="profiel <?= (get_the_time('U') > (time()-60)) ? 'new' : '' ?>">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.