Skip to:
Content
Pages
Categories
Search
Top
Bottom

Limit one forum to topics started today

  • @leggo-my-eggo

    Member

    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • @leggo-my-eggo

    Member

    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. :)

    @leggo-my-eggo

    Member

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar