Skip to:
Content
Pages
Categories
Search
Top
Bottom

Full Content of Most Recent Post on Front-Page?

  • @yottabite

    Member

    Is there any way to make a function, say: “get_latest_topic”, or simply limit the “get_latest_topics” function to display only the latest topic, but also include the full post?

    If not, there may be some other way that I am missing in order to add the content of the latest post to the frontpage, without going all-out and using Worpress for this view.

    Thanks in advance!

Viewing 20 replies - 26 through 45 (of 45 total)
  • @outchy

    Member

    thank you, i will try that.

    any idea about the “invalid argument” error i’m getting?

    @fel64

    Member

    What does it say at /Library/WebServer/Documents/bb-templates/superbold/front-page.php on line 13? Also the significant surrounding lines. Would be kind of useful to know.

    @outchy

    Member

    sure, here is line 13:

    foreach($forum_one_topics as $topic) :

    and here is the surrounding stuff:

    <h2><?php _e('Latest Post'); ?></h2>

    <?php
    $forum_id = 1;
    $forum_one_topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC LIMIT 0,1") ?>
    <?php
    foreach($forum_one_topics as $topic) :
    $forum_one_topic_posts = get_thread( $topic->topic_id); ?>
    Re: <a>"><?php topic_title(); ?></a>

    <span class="gray">
    <a>">
    <?php echo $topic->topic_last_poster_name; ?></a> said:</span> <span class="justify"><?php echo $forum_one_topic_posts[0]->post_text;
    endforeach;
    ?></span>

    @fel64

    Member

    $forum_one_topics is not an array which is why it’s failing (although I’m surprised it’s not).

    Do you actually want the 1 latest topic from forum 1? Then use $bbdb->get_row() instead of get_results() and stop treating it as an array (basically, just take out the foreach part since you don’t have several, and replace $topic with $forum_one_topics).

    If you want all the topics from forum one, then take out the LIMIT 0, 1 bit from the query which as I understand it would give you only one result.

    Also, you have some malformed HTML just under span gray.

    @outchy

    Member

    i want to display the most recent post, no matter what forum it happens to be from. is that possible?

    i tried doing what you said but maybe i messed it up because i’m getting a mysql syntax error. here is what i have, forgive me if it looks glaringly stupid:

    <?php
    $forum_id = 1;
    $forum_one_topics = $bbdb->get_row("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_time DESC ") ?>
    <?php
    $forum_one_topic_posts = get_thread( $forum_one_topics->topic_id); ?>
    Re: <a href="<?php topic_link(); ?>"><?php topic_title(); ?></a>
    <span class="gray">
    <a href="<?php get_user_profile_link( $id = 0, $page = 1 ); ?>">
    <?php echo $forum_one_topics->topic_last_poster_name; ?></a> said:</span> <span class="justify"><?php echo $forum_one_topic_posts[0]->post_text;
    ?></span>

    sorry, i’m really trying to get it :/

    @fel64

    Member

    Sure that’s possible. :)

    You want a query that gives you the last post. Forget anything messing around with the forum or the topic. You want the last post, right?

    There’s no API function to do this AFAIK, so you will have to use a query. I think the structure could go something like this:

    $latestpost = $bbdb->get_row("
    SELECT *
    FROM $bbdb->posts
    WHERE post_status = 0
    LIMIT 1
    ");

    And then $latestpost has $latestpost->post_text, poster_id and so on. But unfortunately not filtered, so you’d need to apply all those. Which is a bit nasty.

    But this is all unchecked and unresearched, you’ll need to play around with it. :P All this is is a bare start.

    @outchy

    Member

    ok cool, thank you. it’s doing something so that’s good :)

    this is what i’m using:

    <?php
    $latestpost = $bbdb->get_row("
    SELECT *
    FROM $bbdb->posts
    WHERE post_status = 0
    LIMIT 1
    ");
    ?>

    <?php echo $latestpost->post_text; ?>

    it’s displaying the first post from forum 3 for some reason, not the most recent post. i’ve posted a few new posts since then in other forums and it never changes on the front page, it still shows that first post from that forum 3. any idea how come?

    (thanks for your help on this)

    @sambauers

    Participant

    You’ll need to order that query by using ORDER BY post_time DESC. There is no guarantee that the last row of a table is the last row that was added.

    @outchy

    Member

    yes, that worked, thank you.

    i’m going through the template-functions.php trying to find how to display the last poster’s username and his/her profile link, as well as the link to the topic itself but the only ones i can get to work are these:

    <?php echo $latestpost->post_text; ?>

    <?php echo $latestpost->poster_id; ?>

    <?php echo $latestpost->post_time; ?>

    any suggestions? :)

    @fel64

    Member

    I don’t know which ones you had problems with but it’s worth noting that some automatically echo and some don’t.

    <?php user_profile_link(); ?>

    =

    <?php echo get_user_profile_link(); ?>

    If they’re get_anything then you have to echo them yourself, if they don’t have get_* then it’ll echo on its own.

    [Edit] Also remember most functions don’t need a $user_id passed as parameter but won’t work in this case unless you do pass it.

    @_ck_

    Participant

    er, nevermind me, you’re doing it within bbpress…

    @outchy

    Member

    so to get the last poster’s username to display, do you do something like this?

    <?php echo get_user_name($user_id); ?>

    i guess i don’t understand the whole passing parameters thing :/

    @outchy

    Member

    wait, i got this to work to display the name:

    <?php echo get_user_name($latestpost->poster_id); ?>

    and this to make it into a link to the person’s profile:

    <a href="<?php user_profile_link($latestpost->poster_id); ?>"><?php echo get_user_name($latestpost->poster_id); ?></a>

    now all i need is to display the topic title and make it a link … i need help with this one please :)

    @fel64

    Member

    That’s great! Passing parameters is just giving the function some data to work with.

    $latestpost->topic_id is the topic ID. There are probably some functions like topic_title() and link_to_topic() or similar that you can use to get the title and link. They too will need the topic ID passed as a parameter, so if those are the actual functions it could be topic_title( $latestpost->topic_id ); :)

    @outchy

    Member

    excellent! i got it to work with this just before i checked back for your reply:

    <a href="<?php echo get_topic_link($latestpost->topic_id); ?>"><?php echo get_topic_title($latestpost->topic_id); ?></a>

    i think i understand it better now, thanks again! :D

    @fel64

    Member

    Cool. :) Can you post the entirety of the code you’re using now, in case someone else will be looking through the forums for a full solution?

    @outchy

    Member

    yes, good call:

    <?php
    $latestpost = $bbdb->get_row("
    SELECT *
    FROM $bbdb->posts
    WHERE post_status = 0

    ORDER BY post_time DESC
    LIMIT 1

    ");
    ?>

    Re:
    <a href="<?php echo get_topic_link($latestpost->topic_id); ?>"><?php echo get_topic_title($latestpost->topic_id); ?></a>:<br /><br />

    <a href="<?php user_profile_link($latestpost->poster_id); ?>"><?php echo get_user_name($latestpost->poster_id); ?></a> said:

    <?php echo $latestpost->post_text; ?>

    @outchy

    Member

    how does one filter the output for time in this example?

    <?php echo $latestpost->post_time; ?>

    i’d like it to be in the format of ( 'g:i A' )

    ps, my good, good people :)

    how would i turn this link into a link to the latest reply itself instead of just the topic:

    <a href="<?php echo get_topic_link($latestpost->topic_id); ?>"><?php echo get_topic_title($latestpost->topic_id); ?></a>

    @fel64

    Member

    Turn the time-string into a timestamp to be turned into a time-string.

    <?php echo date( 'g:i A', strtotime( $latestpost->post_time ) ); ?>

    There’s a template function that gives you the link to the latest post in the topic. I believe it’s called get_topic_last_post_link() but I’m not sure.

    @jenz

    Member

    If I used:

    <?php
    $forum_id = 1;
    $number_of_topics = 7;
    $forum_one_topics = $bbdb->get_results("SELECT * FROM $bbdb->topics WHERE forum_id = $forum_id ORDER BY topic_id DESC LIMIT 0,$number_of_topics")
    ?>
    <?php
    foreach($forum_one_topics as $topic) : $forum_one_topic_posts = get_thread( $topic->topic_id); ?>

    (as see at the beginning of this topic) – how can I show the initial topic time on the front page instead of the last reply time?

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