Hello,
after reading so many interesting posts here in the Webflow-forums, now my first question/problem:
I’m currently trying to build a notification-badge in my top-navigation, to inform my visitors, that since their last visit, new posts have been published. I know its pretty complex to get the actual count of new posts, but maybe someone is able to take this code-snippet (coming from an unread-posts plugin of Wordpress) and get it to work with the cookies set by webflow (cookie-js?)
function wpb_lastvisit_the_title ( $title, $id ) {
if ( !in_the_loop() || is_singular() || get_post_type( $id ) == 'page' ) return $title;
// if no cookie then just return the title
if ( !isset($_COOKIE['lastvisit']) || $_COOKIE['lastvisit'] == '' ) return $title;
$lastvisit = $_COOKIE['lastvisit'];
$publish_date = get_post_time( 'U', true, $id );
if ($publish_date > $lastvisit) $title .= '<span class="new-article">New</span>';
return $title;
}
add_filter( 'the_title', 'wpb_lastvisit_the_title', 10, 2);
// Set the lastvisit cookie
function wpb_lastvisit_set_cookie() {
if ( is_admin() ) return;
$current = current_time( 'timestamp', 1);
setcookie( 'lastvisit', $current, time()+60+60*24*7, COOKIEPATH, COOKIE_DOMAIN );
}
add_action( 'init', 'wpb_lastvisit_set_cookie' );
Source of code: http://www.wpbeginner.com/wp-themes/how-to-highlight-new-posts-for-returning-visitors-in-wordpress
Thanks in advance and kind regards,
Michael