Support Forum

Template tags for table of recent posts?

PK pkthree
pkthree
Member

Hi,

Is there a template tag in 5.1.3 that can produce table displays similar to sf_recent_posts_expanded() from 4.x? It output table displays of topics that were recently posted to, with a parameter for the forum ID (defaulting to ALL forums) and a parameter for the number of topics to show. The table display for topics with most recent posts across all forums would look like the home page of http://www.highinterestsavings.ca/

11 Answers

New Answer

JS Jakob Smith
Jakob Smith
Member

I’m on the lookout for exactly the same thing, so  following this thread.

I need to show a table with the 5 most recent posts with topic, forum, author and date. Tried tweaking the Recent Forum Posts widget but it didn’t work.

The table is to be shown in a widget on a frontpage with lots of other widgets. PHP code will be fine.

YS Yellow Swordfish
Yellow Swordfish
Member

I think this should be what you are looking for:

http://codex.simple-press.com/codex/plugins/our-plugins/the-template-tags-plugin/template-tag-recent-posts/

Also available as a widget.

JS Jakob Smith
Jakob Smith
Member

Thank you.

Using the shortcode + CSS, I ended up building a table-like structure, which fits my need.

I found out that I can put HTML into the befores and afters:

sp_recent_posts itemorder='TFUD' limit='4'
beforeTopic='<div class="spdebatforside-emne">' afterTopic='</div>' 
beforeForum='<div class="spdebatforside-forum">' afterForum='</div>' 
beforeUser='<div class="spdebatforside-navn">' afterUser='</div>' 
beforeDate='<div class="spdebatforside-dato">' afterDate='</div>'

Around this I’m putting other HTML to build the rest of the structure. It is all put into a content block using Custom Post Widget and they I insert the content block in the right widget area on the frontpage.

YS Yellow Swordfish
Yellow Swordfish
Member

Getting quite fascinated to see this site :)

MP Mr Papa
Mr Papa
Member

Peter, sorry, looks like your question got skipped…  No, we did not convert over the recent posts expanded template tag…  at least not in its current form…

the reason primarily being that with themes now, we didnt come up with a particularly slick method of making it look the same… with v4 skins, we pretty much knew how it would look…

with v5 now and themes, the recent posts and other similar tags, use a template file for styling the output…  so you could redo the default template file that we provide and try to make the style identical…  not sure all the data is available in the class, but if not its easily added with a couple filters and hooks…

I should add that the recent posts tag does take a specific forum id if desire and limit the recent topics to that forum..  and number of topics…  it does everything you want, I believe, except duplicate the output styling of the forum…  but that is customizable as mentioned in above paragraph…

PK pkthree
pkthree
Member

In modifying sp_RecentPostsTag() to add some extra information, I encountered what I think is a bug around showing first post information in the spTopicList class: in sp_listview_query(), first post information is loaded via:

$first = spdb_table(SFPOSTS, "topic_id=$r->topic_id AND post_index=1", 'row');

Then the display name is accessed via:

$list[$t]->first_display_name = sp_filter_name_display($first->display_name);

However, the display name is not stored in the posts table, so this is always blank. Presumably the original fetch needs to join the user ID to the members table OR we would just do a conditional extra database query if the user ID isn’t NULL?

YS Yellow Swordfish
Yellow Swordfish
Member

Are we looking at the same thing? The sp-list-topic-class.php file? Because the $first data object is populated with the following query:

spdb_select('row', 'SELECT * FROM '.SFPOSTS.' JOIN '.SFMEMBERS.' ON '.SFMEMBERS.'.user_id = '.SFPOSTS.".user_id WHERE topic_id=$r->topic_id AND post_index=1");

on code line 255 of the most recent file?

YS Yellow Swordfish
Yellow Swordfish
Member

Ah yes – you are quite correct. I didn’t know that!
Yes that was the only change.
But it isn’t really very efficient going off and making a db call with a join for every row… I need to look at that…

PK pkthree
pkthree
Member

To somewhat close off the topic, here are some notes on building your own “template tag”.

I found myself making a few too many tweaks to sp_RecentPostsTag() (for example, for different date formatting) and decided to build my own function, which I must emphasize is not a bad outcome from a development perspective. sp_RecentPostsTag() provides many parameters to tweak the HTML output of the template tag, but I don’t think its job should be to provide for every possible tweak. So a pure separation of content and design is nice here, and easily achievable in a custom function with these basic elements:

// Make all necessary includes and definitions
sp_forum_api_support();

// Get ONLY the data for the most recent topics
$spTopics = new spTopicList( $topicIds, $limit, $orderByGroup, $forumIds, $firstPost );

// Format the output in whatever way you want:
foreach( $spTopics->listData as $spTopic )
// … and so on

YS Yellow Swordfish
Yellow Swordfish
Member

Excellent. We certainly hope we have provided a rich enough data object for peoples needs but always feel free to shout if you feel it is lacking in any way.

The query for the first post details has been made more efficient as well. Using a single row query for every topic is not really the best way so it now just runs a single query to collect all it needs.