Notice: These forums are now retired and closed. For active support, please Submit a Ticket or visit our official WordPress.org community pages.
Kadence Theme | Kadence Blocks | Starter Templates | WooCommerce Email Designer | Ascend | Virtue | Pinnacle

Custom Class if Post is 7 days old

Home / Forums / Kadence Theme / Custom Class if Post is 7 days old

This topic is: Not a support question
[Not a support question]
Posted in: Kadence Theme
February 9, 2021 at 9:37 pm

Hi Ben and Hannah and team

I am using the below code to add a class to a post if it is over 7 days old (so that I can show a “new” badge if the post is new). This works on single post fine, but I can’t get it to work on the archive (categories) pages – it seems these don’t have the same header classes – the category pages are all displaying posts listed with the “blog_grid” siteorigin widget… Any clues how I can get the below to show in these blog grid posts?

` function is_new_post($class) {
global $post;

$id = get_the_ID();
$date = get_the_date( $format, $id );

if( strtotime( $date ) < strtotime( “-7 days” ) ) { // if post is 7 days old or less
$class[] = ‘-NEW’;
} else {
$class[] = ‘-OLD’;
}

return $class;

}
add_filter(‘post_class’, ‘is_new_post’);
`

I think what is happening is that the single posts have an <article> tag that the above is prepending the new class to, but with the blog grid, there is no <article> tag, only “class=”entry-title”

  • This topic was modified 5 years, 2 months ago by Solace.
  • This topic was modified 5 years, 2 months ago by Solace.
  • This topic was modified 5 years, 2 months ago by Solace.
  • The forum ‘Kadence Theme’ is closed to new topics and replies.