Skip to:
Content
Pages
Categories
Search
Top
Bottom

a link on the picture


  • frenchlemans
    Participant

    @frenchlemans

    Hello,

    In my page where the list of subjects appears, I would like the image of the board on the right to be linked to the last message posted in the subject.
    I have made various attempts but each time I am referred to the last post of the forum and not of the subject.
    Do you have a solution for me?

    Thank you and good day.

    link picture

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

  • Robin W
    Moderator

    @robin-w

    what is your existing code?


    frenchlemans
    Participant

    @frenchlemans

    Hello Robin,

    I tried to adapt the code you provided me for the same function but from forums and not topics. I tried a lot of possibilities inside but each time it brings me back to the last forum and not to the last post of each topic.
    I searched through the documentation and archives but couldn’t find anything.
    So the code used is below, it fits the image well but not the last post of the subject in which it is:

    add_action( 'bbp_theme_after_topic_freshness_author', 'rew_freshness_display_reply');
    function rew_freshness_display_reply ($forum_id = 0) {
    	// Verify forum and get last active meta
    	$forum_id  = bbp_get_forum_id( $forum_id );
    		$active_id = bbp_get_forum_last_active_id( $forum_id );
    		$link_url  = $title = '';
    
    		if ( empty( $active_id ) )
    			$active_id = bbp_get_forum_last_reply_id( $forum_id );
    
    		if ( empty( $active_id ) )
    			$active_id = bbp_get_forum_last_topic_id( $forum_id );
    
    		if ( bbp_is_topic( $active_id ) ) {
    			//then reset forum_id to the forum of the active topic in case it is a sub forum
    			$forum_id = bbp_get_topic_forum_id($active_id);
    			$link_url = bbp_get_forum_last_topic_permalink( $forum_id );
    			$title    = bbp_get_forum_last_topic_title( $forum_id );
    		} elseif ( bbp_is_reply( $active_id ) ) {
    			//then reset forum_id to the forum of the active topic in case it is a sub forum
    			$forum_id = bbp_get_reply_forum_id($active_id);
    			$link_url = bbp_get_forum_last_reply_url( $forum_id );
    			$title    = bbp_get_forum_last_reply_title( $forum_id );
    		}
    		
    		$anchor = '<a class="rew_freshness_display_image" href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '"><img class="plato" style="width: 29px; height: 20px;" src="https://webershoot.com/mesimages/transplato.png">' . '</a>';
    	
    echo '<p class="platopost">'.$anchor.'</p>';
    }

    Regards.


    Robin W
    Moderator

    @robin-w

    Try

    add_action( 'bbp_theme_after_topic_freshness_author', 'rew_freshness_display_reply');
    function rew_freshness_display_reply ($forum_id = 0) {
    	// Verify forum and get last active meta
    	$forum_id  = bbp_get_forum_id( $forum_id );
    		$active_id = bbp_get_forum_last_active_id( $forum_id );
    		$link_url  = $title = '';
    
    		if ( empty( $active_id ) )
    			$active_id = bbp_get_forum_last_reply_id( $forum_id );
    
    		if ( empty( $active_id ) )
    			$active_id = bbp_get_forum_last_topic_id( $forum_id );
    
    		if ( bbp_is_topic( $active_id ) ) {
    			//then reset forum_id to the forum of the active topic in case it is a sub forum
    			//$forum_id = bbp_get_topic_forum_id($active_id);
    			$link_url = bbp_get_forum_last_topic_permalink( $forum_id );
    			$title    = bbp_get_forum_last_topic_title( $forum_id );
    		} elseif ( bbp_is_reply( $active_id ) ) {
    			//then reset forum_id to the forum of the active topic in case it is a sub forum
    			//$forum_id = bbp_get_reply_forum_id($active_id);
    			$link_url = bbp_get_forum_last_reply_url( $forum_id );
    			$title    = bbp_get_forum_last_reply_title( $forum_id );
    		}
    		
    		$anchor = '<a class="rew_freshness_display_image" href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '"><img class="plato" style="width: 29px; height: 20px;" src="https://webershoot.com/mesimages/transplato.png">' . '</a>';
    	
    echo '<p class="platopost">'.$anchor.'</p>';
    }

    frenchlemans
    Participant

    @frenchlemans

    Hello robin

    Thanks for the function.
    It does not work well, it recalls the last post of all the topic of a forum in its category but not the last post of a topic on the same line.

    Here is the link to see what I’m saying :
    my page topics

    Regards


    Robin W
    Moderator

    @robin-w

    might have been too complicated, maybe just try

    add_action( 'bbp_theme_after_topic_freshness_author', 'rew_freshness_display_reply');
    
    function rew_freshness_display_reply ($topic_id = 0) {
    		$topic_id   = bbp_get_topic_id( $topic_id );
    		$link_url   = bbp_get_topic_last_reply_url( $topic_id );
    		
    		$anchor = '<a class="rew_freshness_display_image" href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '"><img class="plato" style="width: 29px; height: 20px;" src="https://webershoot.com/mesimages/transplato.png">' . '</a>';
    	
    echo '<p class="platopost">'.$anchor.'</p>';
    }

    frenchlemans
    Participant

    @frenchlemans

    Thanks Robin,

    I just added the “title” line because it came out with an error.
    Otherwise it works very well.

    $title = bbp_get_forum_last_reply_title( $topic_id );
    I think this function can be useful to other people.

    Have a good day.


    Robin W
    Moderator

    @robin-w

    great – glad you are fixed !

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