Skip to:
Content
Pages
Categories
Search
Top
Bottom

Post_Text Front Page

  • Is it possible to display the topic starters post_text on the front page? I’ve run into a forum explaining how to do something similar by using functions, however it only shows a snippet. I want it to display fully including possible images that may be included.

    I’m hoping this can be done without a plugin.

Viewing 14 replies - 1 through 14 (of 14 total)
  • A bit surprised no one has chimed in yet, didn’t think it was that difficult to achieve.

    Anyways here is the code that I found in another thread:

    <?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;
    }
    ?>

    I figured it’s the same basis, however since I’m pretty much brain dead in regards to php I can’t for the life of me make the post_text show fully. This code strips out html code so links don’t show, how can the code be altered to allow html? I figure this code is similar to WordPress’ content_excerpt. If there is another way, I’m open to suggestions.

    Sorry for all the newbie questions, I assure you I’ve tried my best to track down my issues in the forum search before asking my questions, unfortunately due to lack of a codex and documentation I’m pretty much at a lost.

    If I understand correctly, you are trying to get the first post of the topic in its entirety. If that is the case, use the function bb_get_first_post to get the first post for the topic, which is what is used by the RSS feed. Then, use the post_text function to get the text for the post based on post_id. Using your example above, you would use:

    $post = bb_get_first_post(get_topic_id());

    $post_text = post_text($post->post_id);

    Whenever you can, you should use the built in functions instead of calling the db directly, unless you have a valid reason for doing so. When you use the built in functions, the appropriate filters are called so that any installed plugins can work (One example would be adding rel=no-follow, or target=blank within your links). Only if you are trying to avoid running the plugins, or you are doing something completely custom, should you not use the built in functions.

    Hatter thanks for the lesson, even though most of it was above my head I’m very grateful for your help. Btw your code worked like a charm.

    I feel like an a** since I’ve been littering these boards with newb questions. With that said, I was wondering if you could help me with another minor thing that I have been trying to figure out. In WordPress you can call the_category(); which indicates which category the post is in. I’ve been searching the forum and there was one person who asked the same question but didn’t get a reply can this be done?

    Sorry for hijacking my own post :(.

    You shouldn’t feel bad for asking questions. Everyone has to learn somehow.

    Are you asking how to tell if a forum is in a category? If so, use this function:

    bb_get_forum_is_category( $forum_id )

    This function returns true or false if the forum is a category.

    I guess I made it a little confusing with the category reference to WordPress.

    You’re on the right track, but what I’m looking for is detecting what forum a topic is in, this will be used by title in the front_page as well the titles in the topic_pages.

    Illustration:


    Topic Title

    File under: Forum 1


    Making the forum link linkable would be ideal as well. Thanks.

    Ok, I see what you’re looking for now. To get the forum name, use the forum_name() function and to get the forum link, use the forum_link() function. Once you have the topic ID, use the get_topic() function to get the topic object. From here, you can use the forum id. So, your code would look like:

    $topic = get_topic($topic_id);

    $forumName = forum_name($topic->forum_id);

    $forumLink = forum_link($topic->forum_id);

    An example of the forum_name and forum_link functions being used is in the bb-templateskakumeiforum.php file. Keep in mind that the example uses the current forum_id and doesn’t pass it in, but this should give you an example of how to use them.

    forum_name works correctly in the topic template, however it doesn’t seem to work in the front-page template.

    That’s odd that it wouldn’t work in the front-page.php template file, since it is used within there. Make sure you are calling it correctly and that your code is hit. Can you post a code snippet for how you’re calling it?

    I literally just copied the code you provided and pasted it in the front-page.php template file and topic.php template file. The front-page template shows the url however it does not display the forum name. The topic template shows the forum url and the forum name.

    This is what I put in the template files:

    <?php $topic = get_topic($topic_id);
    $forumName = forum_name($topic->forum_id);
    $forumLink = forum_link($topic->forum_id); ?>

    Ah, copying the exact code would be the problem. That was meant as a guide, meaning you need to pass in the correct topic ID into the get_topic function. Depending on where in the front-page template you are putting this, you need to get the correct / current topic id.

    I’m a little confused, please bare with me :). If I put in a topic id wouldn’t that just read out the same forum name by the file under: ?

    To clarify I will be putting the code in the topic template as well as the front-page template which will show the latest discussions. Problem is if I put in a topic id wouldn’t it just read that all the topics are under one category?

    Heh, looks like I’m learning a few things from you. I added this $topic = get_topic(get_topic_id()); and it automatically got the topic id. Thanks for the help and lesson.

    You beat me to it :) Glad you figured it out. Just to clarify, what I mean was you need to pass the proper topic ID depending on what you are doing. In this case, you are using get_topic_id(), which will get the current topic ID being worked on based on the global topic object. In other cases, you may be within a loop of topics, in which case you would need to use something along the lines of $topic->topic_id, depending on your topic object name. This will start to make more sense as you progress within php and bbPress. Until then, don’t be afraid to ask questions for help, everyone has to learn somehow.

    Funny thing is that is what I’m planning on delving into next. I’m new to bbPress but decided to try it out because I was familiar with WordPress. I don’t have any formal training in code, I’ve pretty much just learned by piecing things together and seeing if they work.

    Back to my original train of thought, I’m planning on implementing something like queries, which I think is what you mean by loop of topics. I was actually browsing around the forums looking for ways to pull related topics together not by keywords but by relation to forums. I plan on putting this within the topics template to display similar topics to members. Will definitely be looking for help on that one as I’m sure it won’t be as easy to implement as in WordPress.

    I was planning on using <?php if (in_category() ): ?>, that is what I used in WordPress to pull similar posts together. However I’m wondering if this approach is possible in bbPress because I’m not sure if there is such a thing as in_category. I guess this will be another thing to get into. Will check back after I take a much needed rest. Thanks again.

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