Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change Post Order Question

  • @wilcowilcox

    Member

    Is it possible to change the order of posts, so that the most recent appears at the top of the page, and the origional post at the bottom?

    Cheers.

Viewing 12 replies - 1 through 12 (of 12 total)
  • @mdawaffe

    Member

    The easy way is to find get_thread( $topic_id, $page ) in /topic.php and change it to get_thread( $topic_id, $page, true ).

    The better way is to use a plugin so that you aren’t modifying any core files. (This is untested)

    <?php

    /*

    Plugin Name: Reverse Post Order

    Plugin URI: https://bbpress.org/forums/topic/76

    */

    function reverse_post_order() {

    global $topic_id, $page, $topic, $bb_current_user;

    global $bb_db_override, $posts, $forum, $tags, $user_tags, $other_tags, $list_start;

    $bb_db_override = true;

    $posts = get_thread( $topic_id, $page );

    $forum = get_forum ( $topic->forum_id );

    $tags = get_topic_tags ( $topic_id );

    if ( $bb_current_user && $tags ) {

    $user_tags = get_user_tags ( $topic_id, $bb_current_user->ID );

    $other_tags = get_other_tags ( $topic_id, $bb_current_user->ID );

    } elseif ( is_array($tags) ) {

    $user_tags = false;

    $other_tags = get_public_tags( $topic_id );

    } else {

    $user_tags = false;

    $other_tags = false;

    }

    $list_start = ($page – 1) * bb_get_option(‘page_topics’) + 1;

    post_author_cache($posts);

    }

    add_action( ‘bb_topic.php_pre_db’, ‘reverse_post_order’ );

    ?>

    @wilcowilcox

    Member

    Thanks very much, I will have a go with this tonight!

    @outchy

    Member

    worked for me, good stuff. thanks!

    @outchy

    Member

    is there a way to change the text styling of the most recent topic line of the front page? in other words, i already have the posts sorted so the most recent is always on the top line i’d really like to always have that line be, say, in bold or in a different color. is that possible?

    @fel64

    Member

    The first line of the first post? Or do you mean the first thread in the first thread listing?

    Sure, just do something like this. <?php if( !$is_foist_topic ) { echo ‘ class=”first-topic”‘; $is_foist_topic = true; } ?>

    The first time it checks it won’t be true, so it echoes code to change the class of the HTML. Then it sets it to true, so the next times it will be true and it’ll skip that.

    You want the code to set the class of the tr I believe, so put it in the HTML for that. Play around.

    @walkingisoverrated

    Member

    I copied the above plugin text to my html editor, saved as reverse.php and uploaded it to /my-plugins and activated it – but nothing happened! Ideas? :/

    @trent

    Member

    As mdawaffe mentioned, it was untested. As well, there have been core changes since, so somebody would have to ‘debug’ that little plugin. Anyone notice anything off the cuff on why it doesn’t work?

    Trent

    @3ring

    Member

    Hey Mods;

    (Tried to install plugin, got fatal error, so tried code file edit…)

    I just want one post to have reverse order, so I tried:

    if ( !$bb_db_override ) :

    if ($topicid == '54') {

    $posts = get_thread( $topic_id, $page, true );

    } else {

    $posts = get_thread( $topic_id, $page );

    }

    $forum = get_forum ( $topic->forum_id );

    $tags = bb_get_topic_tags ( $topic_id );

    But it doesn’t seem to recognize the topic id – it displays all posts normally? Am I assuming wrongly that the topic_id is the number after “/topic/##” in the thread url?

    Can you see anything I’m doing wrong? How do I isolate a single post to be reverse order?

    Thanks!

    @fender

    Member

    I’ve been playing with this one and there’s a modification I would mind seeing, or some help on how to make the modification.

    I’m trying to use the AJAX Quote plugin with this, but unfortunately it breaks. The reason is simple … the AJAX Quote plugin basically copies the id=x&page=y#post-zz into the postbox so that you can find and navigate to the original post being quoted. When using this script, it gets broken because the most recent posts are always on page=1, meaning that when a post that’s been replied to gets bumped to page=2, the link is now incorrect.

    What I’d like to see is that the page id’s for a paginated topic don’t change … the earliest post will always be page=1 and the most recent posts will be on the highest page number. I can see that the quoting system can still be broken if the posts per page setting is changed, I know. But assuming it doesn’t change, then this would maintain the integrity of the quote links.

    Any ideas?

    @nightgunner5

    Member

    @Fender:

    You would need to have the link put into the post at the time of display, not at the time of posting. I already emailed you the plugin you asked for. ;)

    @fender

    Member

    I’ll have to check it out. I agree with you, I think I sent you an email with a description of how it would need to work and how it could be used in a way that didn’t break pagination, pagination config changes and quoting plugins.

    Hi!

    Does anyone have some advice as to how to apply this fix so that it doesn’t mess with the pagination … ?

    Thanks.

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