Forums

Join
bbPress Support ForumsTroubleshootingshow a snippet of the post under the topic title?

Info

show a snippet of the post under the topic title?

  1. Is there a way to show a snippet of the post (limit 200 characters) under the topic title on the front page? I tried putting in "<?php post_text(); ?>" but nothing showed up. Any ideas?

  2. Create a functions.php file in your theme folder, and write this in it:

    <?php
    function get_post_teaser($chars = 200){
    	global $bbdb;
    	$topic_id_ft = get_topic_id(); //topic id for getting text of first post of the topic
    	$first_post = (int) $bbdb->get_var("SELECT post_id FROM $bbdb->posts WHERE topic_id = $topic_id_ft ORDER BY post_id ASC LIMIT 1");
    	$content = substr(strip_tags(strip_shortcodes(get_post_text($first_post))),0, $chars); //gets the first 200 chars of the post
    	return $content;
    }
    ?>

    Then at the front page, put this where you need to display the post text (it should be inside the loop):

    <?php echo get_post_teaser(200); ?>

    You can change that 200 to anything, any number of letters you want. Default is 200.
    I think, this should work.

  3. Thank you that worked!

  4. You must log in to post.