Skip to:
Content
Pages
Categories
Search
Top
Bottom

sticking a reply at the top of the repies


  • Clivesmith
    Participant

    @clivesmith

    I am trying to stick a reply at the top of the replies page, can anyone help please.
    to explain..
    I have a forum called countries containing
    forums for each country, inside each country (forum) are topics called airport names,
    inside each topic (airport names) are replies, I would like to stick one of the replies to the top of the list of replies for that airport, the one I want to stick is unlikely to be the first entry for that airport.
    I hope that makes sense.

    WordPress 4.9.6 running twentytwelve child theme theme, bbpress Version 2.5.14

    the website is https://wateratairports.com

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

  • Clivesmith
    Participant

    @clivesmith

    Hi sorry to bump but does anyone have any ideas please ?


    wpGonzales
    Participant

    @wpgonzales

    Hi, I found the plugin “bbpress Sort Topic Replies” https://wordpress.org/plugins/bbpress-sort-topic-replies/ can do that, but only for the first reply of a thread. Also, the plugin has not been updated for a long time, it seems to be abandoned.


    Clivesmith
    Participant

    @clivesmith

    Sorry I have just seen this, not sure why I did not get an Email when you replied, I will try that plugin and report back.
    Thanks
    Clive


    Clivesmith
    Participant

    @clivesmith

    Thanks wpgonzales but this seems to just sort up or down, I want to pick a reply and stick that one at the top of that topic.


    Robin W
    Moderator

    @robin-w

    that would take a lot of code, beyond free help


    Clivesmith
    Participant

    @clivesmith

    Hi Robin,

    OK thanks, I will try to look at how the stick to front at topic level works and see if I can adapt it.


    Robin W
    Moderator

    @robin-w

    @clivesmith

    If you fine with code, then this is how I would go about it

    1. create a split in topic & replies, so you have a place to put the ‘featured reply’
    Use this piece of code in your functions file

    bbp_show_lead_topic

    2. then you’ll need a flag for the featured reply.

    This code does an ‘advert’ flag for a topic, but has much of the code you’d need to do a flag for a reply to show it is featured – I’ll leave you to work out which bits you’ll need, but the key is the hook to

    add_action( 'bbp_theme_before_topic_form_submit_wrapper', 'at_checkbox' );

    change this to

    add_action( 'bbp_theme_before_reply_form_submit_wrapper', 'at_checkbox' );

    amend the references from topic to reply

    and add some if(bbp_keymaster() ) to make it only show for you, and you will be most of the way there

    // show the "Mark if it is an advert" checkbox on topic form
    	add_action( 'bbp_theme_before_topic_form_submit_wrapper', 'at_checkbox' );
    		
    function at_checkbox() {
        // Text for the topic form
    	global $topic_advert_text ;
    	?>
    		<p>
    
    			<input name="at_advert" id="at_advert" type="checkbox"<?php checked( '1', at_is_advert( bbp_get_topic_id() ) ); ?> value="1" tabindex="<?php bbp_tab_index(); ?>" />
    
    			<?php if ( bbp_is_topic_edit() && ( get_the_author_meta( 'ID' ) != bbp_get_current_user_id() ) ) : ?>
    
    				<label for="at_advert"><?php echo '<span class="dashicons dashicons-awards"></span>'.$topic_advert_text.'</label>' ;?>
    
    			<?php else : ?>
    
    				<label for="at_advert"><?php echo '<span class="dashicons dashicons-awards"></span>'.$topic_advert_text.'</label>' ;?>
    
    			<?php endif; ?>
    
    		</p>
    <?php
    }
    	
    //check if topic is advert
    function at_is_advert( $topic_id = 0 ) {
    	
    	$retval 	= false;
    
    	if ( ! empty( $topic_id ) ) {
    		$retval = get_post_meta( $topic_id, 'at_topic_is_advert', true );
    	}
    	return (bool) apply_filters( 'at_is_advert', (bool) $retval, $topic_id );
    }
    
    // save the advert state
    		add_action( 'bbp_new_topic',  'at_update_topic' );
    		add_action( 'bbp_edit_topic',  'at_update_topic' );
    
    //update topic 
    function at_update_topic( $topic_id = 0 ) {
    
    		if( isset( $_POST['at_advert'] ) )
    			update_post_meta( $topic_id, 'at_topic_is_advert', '1' );
    		else
    			delete_post_meta( $topic_id, 'at_topic_is_advert' );
    
    	}

    3. amend content-single-topic-lead.php in your child theme’s bbpress directory.

    by

    create a directory on your theme called ‘bbpress’
    ie wp-content/themes/%your-theme-name%/bbpress

    where %your-theme-name% is the name of your theme

    find
    wp-content/plugins/bbpress/templates/default/bbpress/content-single-topic-lead.php
    Make a copy of this file, and put in in the directory called bbpress that you created above, so you end up with
    wp-content/themes/%your-theme-name%/bbpress/content-single-topic-lead.phpbbPress will now use this template instead of the original and you can amend this

    This then you can use to add some code

    if (at_is_advert( $reply_id )) then….. display this reply

    and you should be there

    so

    the reply form will show a checkbox to make a reply featured available only to say keymaster, and as keymaster you can edit a topic to make it a featured
    the content_single_topic_lead will check if a reply is featured and then show it if it is

    I wish I had the time to code this all for you, but please if you do work oyt some code, post back here for other to benefit


    Clivesmith
    Participant

    @clivesmith

    Thanks Robin,

    I will give it a go and let you know if I succeed.

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