Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display list of topics under specific forum


  • ringishpil
    Participant

    @ringishpil

    Hi guys I am trying to list the 3 freshest bbpress topics from a specific forum. How Can I do that?

    This is my code for displaying latest 3 topics from bbpress (not specific forum):

    get_results("SELECT post_title, guid, post_date, post_type, post_modified, post_type from wp_posts where post_type LIKE 'topic' && post_type LIKE 'topic' ORDER by post_date DESC limit 3","ARRAY_N");
    			   if ($forumslist)
    			   {
    				   foreach ($forumslist as $row)
    				   {
    					   echo '<li><a href="'.$row[1].'" rel="nofollow">'.$row[0].'</a>'.date('F d, Y', strtotime($row[2])).'</li>';
    				   }
    			   }
    			   else
    				   echo 'Error fetching data';
    ?>
    

    Now I would like to get the most fresh topics under a certain parent. So I know I can do something like:

    $forumslist1 = $wpdb->get_results("SELECT post_title, guid, post_date, post_modified, post_type, post_parent from wp_posts where post_type LIKE 'topic' && post_parent LIKE '1263' ORDER by post_modified DESC limit 3","ARRAY_N");

    but how can I order those by freshness? You can see I tried to order them by post_modified but I didnt have luck there…

    So I need to know how to get the freshest topics…

    Thanks,
    Mario

Viewing 3 replies - 1 through 3 (of 3 total)
  • This is what I am using as a custom plugin on a site:

    
    if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => 'false', 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'post_parent' => 'any', 'posts_per_page' => 5 ) ) )
    		bbp_get_template_part( 'bbpress/loop', 'topics' );
    

    Where post_parent = ‘any’ forum or change this to a specific forum id

    It is based on this https://gist.github.com/4207064


    ringishpil
    Participant

    @ringishpil

    @Netweb, thanks I got it.

    Now I want to make a reverse function like I want to display all freshest topics except the one I displayed before.

    So I am doing something like:

    
    $left['show_stickies']=false;
    $left['order']='DESC';
    $left['post_parent']!=1263;
    

    and then

    
    if ( bbp_has_topics($left) )
    		bbp_get_template_part( 'bbpress/loop', 'topics' );
    

    but its listing all of the topics.

    When I go like $left['post_parent']=1263; its ok, but when I want a negation (list all topics from all forums except the forum with 1263 ID, then in var dump of $left['post_parent']!=1263; I am getting NULL


    selenii
    Participant

    @selenii

    <?php
    	if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => 'any', 'posts_per_page' => 10 ) ) )
    		bbp_get_template_part( 'bbpress/loop', 'topics' );
    	?>

    I had put this code to my template. But how can I change the post_parent Parameter automatik, that the plugin know in wich forum he is and show me the right topics.

    Thx

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