News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

ssi_recentTopics - how to show slighter older recent topics

Started by Armada, March 07, 2017, 08:58:22 AM

Previous topic - Next topic

Armada

Hiya,

I'm trying to modify the SSI.php file to create a list of not quite the latest topics, but topics 5 to 10 from the newest.

So for example:

Latest topic -5
Latest topic -6
Latest topic -7
Latest topic -8
Latest topic -9

You may be wondering why I'm trying to do that.

Well, I'm trying to provide a fall-back for when there are no ads shown in certain positions on the page. The fallback for the top ad position includes the latest four topics using the ssi_recentTopics.

So I'm trying to create a fallback for an ad position further down on the page which will then show another set of recent topics.

I've played about with the values in:

'min_message_id' => $modSettings['maxMsgID'] -35 * min($num_recent, 5),


..but they don't seem to make a difference to the age of the recent topics.

Any help or ideas on how to modify SSI.php for this would be appreciated. Thanks!

Armada
--- SMF Rocks even more than YabbSE---

Kindred

you don't need to modify SSI at all.



$second_set=ssi_recentPosts(10,NULL,NULL,'array');
then just do a foreach, but only echo if the count = 6-10
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Shambles

^ yep, or

$second_set=array_slice(ssi_recentPosts(10,NULL,NULL,'array'), 5);

Kindred

oh, that's cute...

Don't forget that you still have to echo it out, though. :D
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Armada

--- SMF Rocks even more than YabbSE---

Armada

Thanks both for your help. I had to do a bit of digging around as my php is a bit rusty (to say the least), and look at the structure of the array to work out what bits I wanted.

In case it helps anybody.

Say if you want to show number 4 to 7 of your latest topics, and items 8 to 11:


<?php
require("../forum/SSI.php"); 

//This shows items 4 to 7 of the latest topics
   
$second_set=array_slice(ssi_recentTopics(7,NULL,NULL,'array'), 3);
  foreach(
$second_set as $item) {
    
   echo 
$item['link'],' (',$item['board']['link'],')<br>';


//If you want to show the items 8 to 11 just use the bit below, and comment out the block above
echo'<br><br>';
//Oh and you can delete the echo <br><br> above too 
   
$third_set=array_slice(ssi_recentTopics(11,NULL,NULL,'array'), 7);
  foreach(
$third_set as $item) {
    
   echo 
$item['link'],' (',$item['board']['link'],')<br>';
}


?>




The output is for each of the group above will come out in the following format:

QuoteIs this right Does that make sense. (Northbridge)
Gosport Circuit (Electronics)
Component unnamed? (Components)
New Member Question (Moderators Board)

Enjoy :)
--- SMF Rocks even more than YabbSE---

Armada

Another little update on this.

I had to change the line that displays the topic title and board so that it opens in a new tab (or window) as the whole purpose was for this to be a "backup ad" for when ads are not displayed. Unfortunately the backup ads are served by Adsense in an Iframe so any new topic link clicked would end up being displayed in the backup ad space itself (not much use!).

So replace this:

echo $item['link'],' (',$item['board']['link'],')<br>';


with this:


echo '<a href="',$item['href'],'" target="_blank" >',$item['subject'],'</a> <a href="',$item['board']['href'],'" target="_blank" > (',$item['board']['name'],')</a><br>';
--- SMF Rocks even more than YabbSE---

Advertisement: