Skip to:
Content
Pages
Categories
Search
Top
Bottom

how can i show latest thred

Viewing 11 replies - 1 through 11 (of 11 total)

  • Robin W
    Moderator

    @robin-w

    Do you want :

    just the latest reply (or topic is no replies)
    The title or all the body?
    Do you want it in the body or in a sidebar?


    surangaudimedia
    Participant

    @surangaudimedia

    @Robin W
    I want in the body.


    Robin W
    Moderator

    @robin-w

    Do you want :

    just the latest reply (or topic is no replies)
    The title or all the content?


    surangaudimedia
    Participant

    @surangaudimedia

    @robin-w
    the latest topic and content. I dont need toshow replies. Just the last thread’s title and content. Thanks


    Robin W
    Moderator

    @robin-w

    Ok I have worked a way to do it.

    But you will need to

    a) add some code to your child theme’s function file and
    b) add a line of code into the page template your home page is using

    How much capability do you have to do that?


    surangaudimedia
    Participant

    @surangaudimedia

    Yeah I can do it.. Could you please post the code for me? Thanks


    Robin W
    Moderator

    @robin-w

    ok, so drop the following into your functions file

    //  Display just latest topic
    function display_latest_topic() {  
    
    	$topics_query = array(
    					'post_type'           => bbp_get_topic_post_type(),
    					'post_parent'         => $settings['parent_forum'],
    					'posts_per_page'      => '1',
    					'post_status'         => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),
    					'ignore_sticky_posts' => true,
    					'no_found_rows'       => true,
    					'order'               => 'DESC'
    				);
    				
    	$lt_query = new WP_Query( $topics_query );
    		
    	while ( $lt_query->have_posts() ) {
    			
    		$lt_query->the_post();
    			$topic_id    = bbp_get_topic_id( $lt_query->post->ID );
    ?>
    <h2> Latest topic </h2>
    <h3> <a href="<?php bbp_reply_url(); ?>" class="bbp-reply-permalink"><?php bbp_topic_title($topic_id); ?></a></h3>
    		
    <div id="bbpress-forums">
    		
    		<div id="post-<?php bbp_reply_id(); ?>" class="bbp-reply-header">
    
    	<div class="bbp-meta">
    
    		<span class="bbp-reply-post-date"><?php bbp_reply_post_date(); ?></span>
    
    		<a href="<?php bbp_reply_url(); ?>" class="bbp-reply-permalink">#<?php bbp_reply_id($topic_id); ?></a>
    		
    	</div><!-- .bbp-meta -->
    
    </div><!-- #post-<?php bbp_reply_id(); ?> -->
    
    <div <?php bbp_reply_class(); ?>>
    
    	<div class="bbp-reply-author">
    
    		<?php bbp_reply_author_link( array( 'post_id' => $topic_id, 'sep' => '<br />', 'show_role' => true ) ); ?>
    
    		</div><!-- .bbp-reply-author -->
    
    	<div class="bbp-reply-content">
    
    		<?php bbp_reply_content(); ?>
    
    	</div><!-- .bbp-reply-content -->
    
    </div><!-- .reply -->
    </div><!--div bbpress-forums--->
    
    	<?php
    		
    	} }

    and then on your page template add this function where you want it. I’ve wrapped it in an if is_front_page statement so it only shows on the frontpage. You night need to use is_home instead depending on how your blog is set up.

    If you want it in the body, you should put it within the content div, either before or after the loop depending if you want it at the of or bottom of the page. You may need to play a bit !


    surangaudimedia
    Participant

    @surangaudimedia

    hi
    i copy this function in my function.php page but does not work.how to add this function in my page content.


    Robin W
    Moderator

    @robin-w

    Sorry, I failed to add the other bit of code you need !!

    The last paragraph should have read :

    …and then on your page template add this function where you want it.

    <?php if(is_front_page() ) { display_latest_topic () ; } ?>
    

    I’ve wrapped it in an if is_front_page statement so it only shows on the frontpage. You night need to use is_home instead depending on how your blog is set up.

    If you want it in the body, you should put it within the content div, either before or after the loop depending if you want it at the of or bottom of the page. You may need to play a bit !

    If any of that isn’t clear, do come back, but let me know what theme you’re using as well


    surangaudimedia
    Participant

    @surangaudimedia

    @robin-w
    thank you very much for your help form the begging,
    it works as i expected

    i may need more help in the future as well
    thank you again
    that’s great


    Robin W
    Moderator

    @robin-w

    Great, glad you’re fixed, and I learnt some more about how bbpress works along the way, so was a good challenge !

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