News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Using SSI.php to display recent topic titles from certain boards

Started by im1, July 11, 2008, 04:59:11 PM

Previous topic - Next topic

im1

If you look at my page i've got a bit on the sidebar that says "Forum Posts", below my shoutbox.

Its shows two recent topics blocks, one from my chatter boards and another from my download boards. I've done this by fetchin the RSS and displaying on the on the page, however the script doesnt work that great. I would like to use SSI.php to get the same results, does anyone know how I could go about this?

I also need it to display in the same manner how the current script works, in bullet points and a word limit of 70 per topic.

Here my current code if it helps how I wanna display it:

if ( $feed ) {
$rss = fetch_rss( $feed );
echo "Latest Chatter";
echo "<ul>";
foreach ($rss->items as $item) {
$href = $item['link'];
$title = $item['title'];
$varlength = strlen($title);
$limit = 70;

if ($varlength > $limit) {
$title = substr($title,0,$limit)."...";
}
echo "<li><a href=$href>$title</a></li>";
}
echo "</ul><br />";
}

if ( $feed2 ) {
$rss = fetch_rss( $feed2 );
echo "Latest Downloads<br>";
echo "<ul>";
foreach ($rss->items as $item) {
$href = $item['link'];
$title = $item['title'];
$varlength = strlen($title);
$limit = 70;

if ($varlength > $limit) {
$title = substr($title,0,$limit)."...";
}
echo "<li><a href=$href>$title</a></li>";
}
echo "</ul>";
}

metallica48423

you could output the function as an array and format it however you wish.

Something akin to:

<?php

// Include the SSI.php
require_once('path-to-SSI.php');

// Grab the topic information, store it as an array in $row
$row = ssi_recentTopics('number of topics', array('array containing board IDs to exclude'), array('array containing board IDs to include'), array);



Then, you could do something like echo '<pre>', print_r($row), '</pre>';  to show what is currently stored in $row.  From there you can run $row through a foreach loop to stylize each item as you wish
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

im1

I cant get it to work :S

Could you make me an example script or something? I aint great with PHP but im getting there. I need one block to show latest topics from boards 1,3,18 and then another one for 9,10,12,14


metallica48423

Please be patient, i'm not able to be online all the time :)

I see that you're running 1.1 in which case the above is wrong.

for 1.1 the $row line would be


// Grab the topic information, store it as an array in $row
$row = ssi_recentTopics('number of topics', array('array containing board IDs to exclude'), array);
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

Nathaniel

Attached is an example of how you could do what you want. You will have to change the path to the SSI.php file though.

At the bottom of the script is an example of how you can show the data from the SSI.php functions, but you should probably format it differently, that is just the default code copied from the SSI.php function.

In the future, please wait for somebody to reply to your thread, please don't PM me for support.

SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

im1

Thanks LHVWB, thats what I wanted. I just need to edit on thing though...

Heres the current code im using to output the titles...

echo 'Latest Chatter<br>
<ul>';
foreach ($download_recent as $post)
echo '
<li><a href="', $post['href'], '">', $post['short_subject'], '</a></li>
';
echo '
</ul>';


Is there a way I could increase the character length higher than 26 before it cuts it off using "short_subject"?

Nathaniel

Try using, $post['subject'] instead.
      echo 'Latest Chatter<br>
      <ul>';
   foreach ($download_recent as $post)
      echo '
               <li><a href="', $post['href'], '">', $post['subject'], '</a></li>
            ';
   echo '
      </ul>';
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

im1

Quote from: LHVWB on July 12, 2008, 06:18:12 PM
Try using, $post['subject'] instead.
      echo 'Latest Chatter<br>
      <ul>';
   foreach ($download_recent as $post)
      echo '
               <li><a href="', $post['href'], '">', $post['subject'], '</a></li>
            ';
   echo '
      </ul>';

Thats what it was before, but I changed it to the short_subject instead because that one was too long. I want it to show the first 30 characters.

Advertisement: