Skip to:
Content
Pages
Categories
Search
Top
Bottom

Last Post and Time on Single Line – loop-single-forum.php


  • brent0r
    Participant

    @brent0r

    On the forums index under Last Post I have:

    “Title Of the Thread That Was Updated Most Recently”
    “17 hours, 11 minutes ago”

    I am wanting to put the two on a single line.
    eg. “Title of the Thread (7 hours, 11 minutes ago)”

    The area of the loop-single-forum file is as follows:

    <li class="bbp-forum-freshness">
    
    		<?php do_action( 'bbp_theme_before_forum_freshness_link' ); ?>
    
    		<?php bbp_forum_freshness_link(); ?>
    
    		<?php do_action( 'bbp_theme_after_forum_freshness_link' ); ?>
    
    		<p class="bbp-topic-meta">
    
    			<?php do_action( 'bbp_theme_before_topic_author' ); ?>
    
    			<span class="bbp-topic-freshness-author"><?php bbp_author_link( array( 'post_id' => bbp_get_forum_last_active_id(), 'size' => 14 ) ); ?></span>
    
    			<?php do_action( 'bbp_theme_after_topic_author' ); ?>
    
    		</p>
    	</li>
    

    I’ve tried editing this quite a bit but all attempts have failed. Any tips or feedback on how I can display the Thread Title (time posted) on a single line would be greatly appreciated.

    Thank you!

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

  • Robin W
    Moderator

    @robin-w

    bbpress just puts the date and author under freshness.

    Are you using bbp style pack plugin or last post plugin or another plugin to put the title into the freshness column?


    brent0r
    Participant

    @brent0r

    Hi Robin W, I am using bbp style pack (your plugin, right?) to change freshness to Last Post. BTW, love your plugin!

    Also, as well as wanting to have the topic title and date on one line, is it possible to have the 3 most last posts displayed rather than one?

    Thanks again.


    brent0r
    Participant

    @brent0r

    I’ve managed to find a solution, I will add styling later to both topic title and date.
    <a href="<?php bbp_forum_last_reply_url(); ?>"><?php bbp_forum_last_topic_title() && bbp_forum_last_topic_title(); ?> (<?php bbp_forum_last_active_time(); ?>)</a>

    I’d still love to find a way to display 3 last posts rather than just one.


    Robin W
    Moderator

    @robin-w

    in place of your code put back the original

    	<?php bbp_forum_freshness_link(); ?>
    

    and then add this to your functions file

    add_filter( 'bbp_get_forum_freshness_link', 'rew_freshness_last_three' , 100, 6) ; 
    	
    function rew_freshness_last_three ($anchor, $forum_id, $time_since, $link_url, $title, $active_id ) {
    	//set up and run a query to get a list of all topics in this forum that this user can see
    	// Setup possible post__not_in array
    	$post_stati[] = bbp_get_public_status_id();
    
    	// Super admin get whitelisted post statuses
    	if ( bbp_is_user_keymaster() ) {
    		$post_stati = array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() );
    
    	// Not a keymaster, so check caps
    	} else {
    
    		// Check if user can read private forums
    		if ( current_user_can( 'read_private_forums' ) ) {
    			$post_stati[] = bbp_get_private_status_id();
    		}
    
    		// Check if user can read hidden forums
    		if ( current_user_can( 'read_hidden_forums' ) ) {
    			$post_stati[] = bbp_get_hidden_status_id();
    		}
    	}
    	// Parse arguments against default values
    	$r = array(
    		'post_parent'         => $forum_id,
    		'post_type'           => bbp_get_topic_post_type(),
    		'post_status'         => implode( ',', $post_stati ),
    		'ignore_sticky_posts' => true,
    		'posts_per_page' => -1
    		);
    	
    
    	// Create a new query for the topic list
    	$get_posts = new WP_Query();
    
    	$topics = $get_posts->query( $r ) ;
    	
    	//var_dump ($topics) ;
    	
    	//now run through this list and get the last active date of each topic
    	foreach ($topics as $topic) {
    		$id = $topic->ID ;
    		$last_active = get_post_meta( $id, '_bbp_last_active_time', true );
    		$curdate = strtotime($last_active);
    		$show[$curdate] = $id ;
    		}
    	if (!empty ($show)) {
    		//so now we have a list of dates with topic ids, so we need to find the latest 3
    		arsort($show);
    		$count=0 ;
    		foreach ($show as $topic) {
    			$count++ ;
    			?>
    			<a href="<?php bbp_topic_permalink($topic); ?>"><?php bbp_topic_title($topic) ?> (<?php bbp_topic_last_active_time($topic); ?>)</a>
    		<?php
    			if ($count == 3) break ;
    		}
    	}
    	else echo 'No topics' ;
    
    	
    }

    It has to sort through all topics for all forums to work this out, so it may slow your forums index display and get worse as your forum content grows.


    brent0r
    Participant

    @brent0r

    Thanks Robin W, working really well. And thanks for taking your time to help.

    One last question which is kind of related. Is it possible to remove the href link from the date/time of the last post (clean bbpress install)?

    Thanks.


    brent0r
    Participant

    @brent0r

    Update (ran out of editing time) – in my post earlier I used bbp_forum_last_active_time which displays no link. Unfortunately forums with no posts don’t display “No topics” but instead show a time (which is likely when that forum was created?).


    Robin W
    Moderator

    @robin-w

    can you explain that a bit further?

    on my site it shows 3 posts, but if there are no posts, it says ‘no topics’.


    brent0r
    Participant

    @brent0r

    When I use your code above, I get the 3 last posts without a link on the date/time.

    When I am not using your 3 last posts code (different site) from above, bbpress naturally links the last post.
    How would I best go about removing just the link from a single last post in that example?

    I’ve figured that I could use your code as above but change to ($count == 1). I’m obviously not experienced with writing code but to me it seems an excessive way to go about it.


    Robin W
    Moderator

    @robin-w

    you’ve lost me now 🙂

    The key line that does the reference is

    <a href="<?php bbp_topic_permalink($topic); ?>"><?php bbp_topic_title($topic) ?> (<?php bbp_topic_last_active_time($topic); ?>)</a>

    This translates as

    <a href="[topic link]">[topic title] ([date])</a>

    which makes both the topic title and the date a single clickable link and the code shows 3 of these.

    I’m not really sure what you are trying to achieve – I had thought you wanted 3 clickable links on both title and date, which is what the above does.

    If you don’t want the date clickable, then do

    <a href="<?php bbp_topic_permalink($topic); ?>"><?php bbp_topic_title($topic) ?></a> (<?php bbp_topic_last_active_time($topic); ?>)


    Robin W
    Moderator

    @robin-w

    SORRY – just read you post again, and now I think I understand

    on one site you want the code as above

    on another site you just want a single post, but with title and date, but no link on the date – yes ?

    if so then untested but this should be it

    add_filter( 'bbp_get_forum_freshness_link', 'rew_freshness_no_date_link' , 100, 6) ; 
    	
    function rew_freshness_no_date_link($anchor, $forum_id, $time_since, $link_url, $title, $active_id ) {
    	if (!empty ($active_id)) {
    	?>
    	<a href="<?php bbp_topic_permalink($active_id); ?>"><?php bbp_topic_title(active_id) ?></a> (<?php bbp_topic_last_active_time(active_id); ?>)
    	<?php
    	}
    	else echo 'No topics' ;
    }

    brent0r
    Participant

    @brent0r

    Thanks again Robin, yes you’ve understood exactly what I was trying to achieve. I tested the above example, it throws Notice: Use of undefined constant active_id – assumed ‘active_id’ in /var/www/html/wp-content/themes/name/functions.php on line 94

    Once I remove bbp_topic_permalink($active_id) eg. bbp_topic_permalink() it works as it should. (I’m not sure if removing that is the right way to go, but doing so seems to help it work)

    There is one little issue though which I’ve noticed since applying the above. The breadcrumb links now have an additional link and date at the end of the breadcrumb. (example: https://goo.gl/9q3NjW) Posts and the forum index are not effected though.

    Thanks once again 🙂


    Robin W
    Moderator

    @robin-w

    ok, should have tested before sending, but coded it late last night and I have been out all day !

    Now had a chance to try it, and correct code is

    add_filter( 'bbp_get_topic_freshness_link', 'rew_freshness_no_date_link' , 100, 5) ; 
    	
    function rew_freshness_no_date_link($anchor, $topic_id, $time_since, $link_url, $title) {
    	if (!empty ($topic_id)) {
    	?>
    	<a href="<?php echo $link_url; ?>"><?php echo $title ;?></a> (<?php echo $time_since ; ?>)
    	<?php
    	}
    	else echo 'No topics' ;
    }

    brent0r
    Participant

    @brent0r

    So the last revision helps a little, but in my case there is a last post date in the breadcrumbs. (https://goo.gl/6iA5Sn)
    Do you get that when viewing a post?


    Robin W
    Moderator

    @robin-w

    did you change the filter – I was calling the wrong one should be

    add_filter( 'bbp_get_topic_freshness_link', 'rew_freshness_no_date_link' , 100, 5)


    brent0r
    Participant

    @brent0r

    Yes, that also looks like you did change that previously.
    It’s like the breadcrumbs catching this change and adding it.


    Robin W
    Moderator

    @robin-w

    can you post the whole of your code – so I can copy/paste into my file and check what it does on mine


    brent0r
    Participant

    @brent0r

    functions.php

    add_filter( 'bbp_get_topic_freshness_link', 'rew_freshness_no_date_link' , 100, 5) ; 
    	
    function rew_freshness_no_date_link($anchor, $topic_id, $time_since, $link_url, $title) {
    	if (!empty ($topic_id)) {
    	?>
    	<a href="<?php echo $link_url; ?>"><?php echo $title ;?></a> (<?php echo $time_since ; ?>)
    	<?php
    	}
    	else echo 'No topics' ;
    }

    It works perfectly when viewing the category page that lists all topics. When I click the topic however and view the post it displays the following in the breadcrumbs:
    › Forums › General › Mobile General › hi Reply To: test (3 weeks, 2 days ago)

    See how it adds the topic title with (the date) that has its link removed, to the end of the breadcrumb.

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