PDA

View Full Version : if category x contains new posts


PinkMilk
08-16-2013, 03:38 AM
How do you write an if condition to show something if if category x contains new posts?

Dummy code explaination:
<if condition="category 3 has new posts">Show this text</if>

exel
08-16-2013, 03:23 PM
Where are you trying to add that code?

PinkMilk
08-16-2013, 11:50 PM
Where are you trying to add that code?

On forumhome, I don't use forumhome_forumbit_level1_nopost so I'm probably just going to have to write a plugin to query db, tbh I have kind of given up on the idea but if you have a solution it would be much appreciated.

BirdOPrey5
08-20-2013, 03:35 PM
In a plugin on global_start add this code


include('includes/functions_forumlist.php');
global $vbulletin, $lastpostarray;

// call fetch_last_post_array() first to get last post info for forums
cache_ordered_forums(1);
if (!is_array($lastpostarray))
{
fetch_last_post_array(-1);
}

$forumidx = 999; //Set your forum id to check here

$lastpostinfo = (empty($lastpostarray[$forumidx]) ? array() : $vbulletin->forumcache["$lastpostarray[$forumidx]"]);
$forumx = $vbulletin->forumcache["$forumidx"];

$isnew = fetch_forum_lightbulb($forumidx, $lastpostinfo, $forumx);

if ($isnew == "new")
{
//Execute code here if the forumid chosen above contains new posts




}


Replace 999 with the forumid of the forum (or category) you want to check

This works for me, I repeat this code multiple times in the plugin to check multiple forumids-


$forumidx = 998; //Set your forum id to check here

$lastpostinfo = (empty($lastpostarray[$forumidx]) ? array() : $vbulletin->forumcache["$lastpostarray[$forumidx]"]);
$forumx = $vbulletin->forumcache["$forumidx"];

$isnew = fetch_forum_lightbulb($forumidx, $lastpostinfo, $forumx);

if ($isnew == "new")
{
//Execute code here if the forumid chosen above contains new posts




}

PinkMilk
08-21-2013, 06:00 PM
Thank you BOP but dosen't seem to work for me, I did everything as instructed and the execution code is just a simple if else

if ($isnew == "new") {

$newmsg = "Yes";

} else {

$newmsg = "No";
}

and added $newmsg to templates, so not sure where I'm going wrong.

BirdOPrey5
08-21-2013, 06:14 PM
What template are you putting $newmsg in?

PinkMilk
08-21-2013, 06:52 PM
Have tried, forumhome, forumhome_forumbit_level2_post and forumhome_forumbit_level1_nopost

BirdOPrey5
08-21-2013, 07:40 PM
This exact code works for me...

include('includes/functions_forumlist.php');
global $vbulletin, $lastpostarray;

// call fetch_last_post_array() first to get last post info for forums
cache_ordered_forums(1);
if (!is_array($lastpostarray))
{
fetch_last_post_array(-1);
}

$forumidx = 1; //Set your forum id to check here

$lastpostinfo = (empty($lastpostarray[$forumidx]) ? array() : $vbulletin->forumcache["$lastpostarray[$forumidx]"]);
$forumx = $vbulletin->forumcache["$forumidx"];

$isnew = fetch_forum_lightbulb($forumidx, $lastpostinfo, $forumx);

if ($isnew == "new")
{
//Execute code here if the forumid chosen above contains new posts

$newmsg = "Yes";

} else {

$newmsg = "No";



}


In your vBulletin Options -> General Settings -> Thread/Forum Read Marking Type, is it set to Database (automatic forum marking)? It may need to be for this to work.