Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: New Code: show forum posts since last visit


3sixty
Participant

@3sixty

I managed to condense this to about 20 lines of code. Try this (4 steps):

header.php

1. At very top of file, add:

<?php ob_start(); ?>

2. After <?php wp_head() ?>, add:

<?php

if ( bp_has_forum_topic_posts() ) {

global $forum_template; $timestamp=time();

if (isset($_COOKIE[“bp_forum_visits”])) {

$unserialized_cookies = unserialize($_COOKIE[“bp_forum_visits”]);

$unserialized_cookies[$forum_template->topic->topic_id] = $timestamp;

foreach ($unserialized_cookies as $topic_id => $timestamp) {

//keep cookie but unset any serialized data older than 60 days

if( time() > $timestamp+60*60*24*30*2 ) { unset($unserialized_cookies[$topic_id]); }

}

//NEED HELP HERE: unset cookies for any deleted topics. How to do this?

} else {

$unserialized_cookies = array($forum_template->topic->topic_id => $timestamp);

}

$serialized_cookies = serialize($unserialized_cookies);

//set the cookie. the whole thing expires in 60 days if there are no forum visits

setcookie(“bp_forum_visits”, $serialized_cookies, $timestamp+60*60*24*30*2, “/”);

} ?>

<?ob_end_flush(); ?>

forums/forums-loop.php

3. After <td class=”td-title”>, add:

<div style=”float:left; margin-right:5px”>

<?php global $forum_template;

if ($user_topic_visits[$forum_template->topic->topic_id]) {

if ($forum_template->topic->topic_time > date(‘Y-m-d H:i:s’, $user_topic_visits[$forum_template->topic->topic_id])) {

echo ‘<img alt=”new posts since last visit” src=”http://img.photobucket.com/albums/v502/Vidster/newposts.jpg”>&#8217;;

} else {

echo ‘<img style=”width:20px;height:20px” alt=”no new posts since last visit” src=”http://img.photobucket.com/albums/v502/Vidster/nonewposts.jpg”>&#8217;;

}

} else {

echo ‘<img style=”width:20px;height:20px” alt=”no new posts since last visit” src=”http://img.photobucket.com/albums/v502/Vidster/newposts.jpg”>&#8217;;

}

?>

4. Download the icons and upload them to your own server; edit the src= to point to your own server copy of the icons

Skip to toolbar