Advertisement:

Author Topic: Displaying and formating Recent posts outside of forum?  (Read 394 times)

Offline shadav

  • Jr. Member
  • **
  • Posts: 206
  • Gender: Female
Displaying and formating Recent posts outside of forum?
« on: October 09, 2019, 03:56:53 PM »
need a bit, ok a lot, of help
trying to display recent posts of the forum onto my homepage
i've gotten this far

add before the html
Code: [Select]
<?php require("path/to/forum/SSI.php"); ?>and then where I want it to display
Code: [Select]
<?php ssi_recentTopics($num_recent 20$exclude_boards null$include_boards null$output_method 'echo'); ?>
so I mean, it works....
I have an error at the top of the page

Notice: Undefined index: googletagged in /forum/Sources/Subs.php on line 4707

and then
how do I format it to look better and how do I exclude boards... I see in the could exclude_boards but if I put the board numbers nothing displays, i tried
Code: [Select]
<?php ssi_recentTopics($num_recent 20$exclude_boards = (1,2,3,16,17), $include_boards null$output_method 'echo'); ?>
http://askthemuslims.com/

thank you for your help

Offline shadav

  • Jr. Member
  • **
  • Posts: 206
  • Gender: Female
Re: Displaying and formating Recent posts outside of forum?
« Reply #1 on: October 09, 2019, 08:24:38 PM »
thank you but I'm not sure how to do that...

Code: [Select]
<?php

$data 
ssi_recentTopics($num_recent 20$exclude_boards = array(1,2,3,16,17), $include_boards null$output_method 'return');
var_dump($data);
echo 
' <div> <a href="'$data.topic['last_post']['href'], '"><img src="'$data.settings['images_url'], '/icons/last_post.gif" alt="'$data.txt['last_post'], '" title="'$data.txt['last_post'], '" style="float: right;" /></a>'$data.topic['last_post']['anonymous'], '
'
$data.topic['last_post']['time'], '<br />
'
$data.txt['by'], ' '$data.topic['last_post']['member']['link'], '</div>';


 
?>
gives all kinds of Warning: Illegal string offset errors

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,751
  • Master of BBC Abuse
Re: Displaying and formating Recent posts outside of forum?
« Reply #2 on: October 09, 2019, 09:24:48 PM »
Why not just change the HTML in SSI.php so it echoes whatever markup you want? Then you don't have to mess with $data.

All it's doing by default is echoing this lot:

Code: [Select]
echo '
<table border="0" class="ssi_table">';
foreach ($posts as $post)
echo '
<tr>
<td align="right" valign="top" nowrap="nowrap">
[', $post['board']['link'], ']
</td>
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt['by'], ' ', $post['poster']['link'], '
', $post['is_new'] ? '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" /></a>' : '', '
</td>
<td align="right" nowrap="nowrap">
', $post['time'], '
</td>
</tr>';
echo '
</table>';

So you can change that to echo whatever divs/classes/etc suits your front page, as long as you keep the variables.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,502
  • Gender: Male
    • Kindred-999 on GitHub
Re: Displaying and formating Recent posts outside of forum?
« Reply #3 on: October 09, 2019, 10:13:07 PM »
no... changing SSI itself is not a great choice....  it will get erased during upgrades and may conflict with mods.

Seriously -- writing the output into the format/layout you want is simple -- easier than modifying SSI

also, you can shorten the call...
$exclude_these = array(1,2,3,16,17);
$data = ssi_recentTopics(20, $exclude_these, null, 'return');
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,751
  • Master of BBC Abuse
Re: Displaying and formating Recent posts outside of forum?
« Reply #4 on: October 09, 2019, 10:36:29 PM »
If it's simpler than rewriting a little bit of basic markup, it must be really simple.

I suggested rewriting a little bit of markup because the supposedly simpler way seemed to have not been explained in a way that was not confusing.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,502
  • Gender: Male
    • Kindred-999 on GitHub
Re: Displaying and formating Recent posts outside of forum?
« Reply #5 on: October 10, 2019, 03:19:45 AM »
Basically,  it's the same thing,  without editing the core SSI file.

If he takes the code that you posted. Using $data_bit instead of $post, it will work...

Code: [Select]
foreach($data as $data_bit)
 echo ' ........
...
...
...
';
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,751
  • Master of BBC Abuse
Re: Displaying and formating Recent posts outside of forum?
« Reply #6 on: October 10, 2019, 04:02:23 AM »
Ok, so something like this?


Code: [Select]
foreach($data as $data_bit)
echo '
<ul class="custom_list_with_awesome_eye_candy">
<li>
', $data_bit['board']['link'], ']
</li>
<li>
<a href="', $data_bit['href'], '">', $data_bit['subject'], '</a>
</li>
<li>
', $txt['by'], ' ', $data_bit['poster']['link'], '
</li>
<li>
', $data_bit['is_new'] ? '<a href="' . $scripturl . '?topic=' . $data_bit['topic'] . '.msg' . $data_bit['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/dancing_bananas.gif" alt="' . $txt['new'] . '" /></a>' : '', '
</li>
<li>
', $data_bit['time'], '
</li>
</ul>';

And where do you stick that if you're not hacking SSI.php? Just throw it in any old front page template?

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,502
  • Gender: Male
    • Kindred-999 on GitHub
Re: Displaying and formating Recent posts outside of forum?
« Reply #7 on: October 10, 2019, 09:50:13 AM »
yes...   put it in any other file/location....

This is easier than editing SSI directly because it means that you're not editing core files and it will be preserved during an upgrade (probably even across major versions)



was typing from my phone last night, but to anyone copying that code - don't forget the SSI call itself
(think you also had a rogue square brace in the first li....)

Code: [Select]
<?php
require_once('path/to/forum/SSI.php');
$exclude_these = array(1,2,3,16,17);
$data ssi_recentTopics(20$exclude_thesenull'return');

foreach($data as $data_bit)
echo '
<ul class="custom_list_with_awesome_eye_candy">
<li>
'
$data_bit['board']['link'], '
</li>
<li>
<a href="'
$data_bit['href'], '">'$data_bit['subject'], '</a>
</li>
<li>
'
$txt['by'], ' '$data_bit['poster']['link'], '
</li>
<li>
'
$data_bit['is_new'] ? '<a href="' $scripturl '?topic=' $data_bit['topic'] . '.msg' $data_bit['new_from'] . ';topicseen#new" rel="nofollow"><img src="' $settings['lang_images_url'] . '/dancing_bananas.gif" alt="' $txt['new'] . '" /></a>' '''
</li>
<li>
'
$data_bit['time'], '
</li>
</ul>'
;
?>

« Last Edit: October 10, 2019, 03:18:23 PM by Kindred »
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,751
  • Master of BBC Abuse
Re: Displaying and formating Recent posts outside of forum?
« Reply #8 on: October 10, 2019, 02:26:00 PM »
Yes I missed the square brace. I was just typing that off the top of my head in the edit box.

Handy stuff to know. Haven't ever played with SSI myself, but was curious.

Offline shadav

  • Jr. Member
  • **
  • Posts: 206
  • Gender: Female
Re: Displaying and formating Recent posts outside of forum?
« Reply #9 on: October 10, 2019, 03:55:49 PM »
thank you both :)  I think I can play around with this now

question though, how to get the annoying error at the top of the screen to go away

Notice: Undefined index: googletagged in /forum/Sources/Subs.php on line 4707

Offline shadav

  • Jr. Member
  • **
  • Posts: 206
  • Gender: Female
Re: Displaying and formating Recent posts outside of forum?
« Reply #10 on: October 10, 2019, 04:30:06 PM »
bwahahahaha I just caught the danceing_banana.gif.... that would have been a riot if it had actually worked and I didn't catch it :D

Offline Antechinus

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 24,751
  • Master of BBC Abuse
Re: Displaying and formating Recent posts outside of forum?
« Reply #11 on: October 10, 2019, 04:38:08 PM »
:D Beware of any code I write when I'm just doing examples.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,502
  • Gender: Male
    • Kindred-999 on GitHub
Re: Displaying and formating Recent posts outside of forum?
« Reply #12 on: October 10, 2019, 07:02:33 PM »
that googletagged error is from some mod that you have that is not coded correctly
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.