Info
- 3 posts
- 1 voice
- Started 2 years ago by leggo-my-eggo
- Latest reply from leggo-my-eggo
- This topic is not resolved
Limit one forum to topics started today
-
- Posted 2 years ago #
I have a forum called "Today Only" that I would like to show only topics and posts that were made today, so that each day it would be a completely new discussion. I do not want any of my other forums to be affected by this, they will function normally.
Can anyone think of a way to accomplish this?
-
- Posted 2 years ago #
OK, I think I have this one solved. I modified my forum.php file to include this block right before the $topics foreach loop.
<?php if( $forum_id == '4' ) { // If this is the "Today Only" forum (#4), replace the $topics query $today = date('omd'); $today_topics_query = new BB_Query( 'topic', array( 'forum_id' => 4, 'started' => $today, 'order_by' => 'topic_start_time', 'topic_status' => 'all', 'open' => 'all', 'count' => true, 'per_page' => 20 ) ); $topics = $today_topics_query->results; // Here's the array of topics the query returned. } ?>I'll let you know for sure if it works tomorrow. :)
-
- Posted 2 years ago #
I found a much more elegant solution by slightly modifying some other code I found here on the forums. I created a plugin like this:
/* Plugin Name: Filter Today Only Topics */ function filter_today_only_topics($where){ $today_only_forums = array ("4"); // The id# of the Today Only forum(s) foreach($today_only_forums as $forum) { $where .= " AND (forum_id != " . $forum . " OR topic_start_time > CURDATE()) "; } return $where; } add_filter( 'get_latest_topics_where', 'filter_today_only_topics'); add_filter( 'get_latest_posts_where', 'filter_today_only_topics');This has the advantage of working in any list of recent posts without modifying the templates. The counts are still wrong in the forum lists, and I can't find a filter that let's me change the query for just those, but I'll just write a template function for that.
-
You must log in to post.