Skip to:
Content
Pages
Categories
Search
Top
Bottom

show a snippet of the post under the topic title?


  • blah
    Member

    @crackpixels

    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?

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

  • Gautam
    Member

    @gautam2011

    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.


    blah
    Member

    @crackpixels

    Thank you that worked!

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