Skip to:
Content
Pages
Categories
Search
Top
Bottom

help me modifying the plugin

  • @purityboy83

    Participant

    Hi

    I want the thumbnail to appear on the topic
    Search results found a plugin similar to the function I’m hoping for

    bbpress-topic-thumbnails
    https://wordpress.org/plugins/bbpress-topic-thumbnails/

    I want to add one more feature in this plugin.
    With this plugin, thumbnails of all forum topics are displayed

    I only want to use this feature for 1 specific forum
    reason for write topic is because the plugin has not been updated for a long time.

    So I ask for help here

    code is

    
    /*Hooks into the loop-topic.php output to print image*/
    add_action( 'bbp_theme_before_topic_title', 'bee_insert_thumbnail' );
    function bee_insert_thumbnail() {
    
            if((!bee_catch_image() == '')){
            echo('<a href="'); 
        echo(bbp_topic_permalink() . '"><img class="bbp-topic-thumbnail"  width="100%" style="max-width: ' . get_option('thumbnail_size_w') . 'px; max-height: ' . get_option('thumbnail_size_h'). 'px; vertical-align:middle;" src="' . bee_catch_image() . '"/>' .'</a>');
            }
    }
    
    /*Function that retrieves the first image associated with the topic*/
    function bee_catch_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches [1] [0];
      return $first_img;
    }
    

    Anyone can help?
    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • @robin-w

    Moderator

    probably

    $forum_id = bbp_get_topic_forum_id()
            if((!bee_catch_image() == '') && $forum_id = '12345'){

    @purityboy83

    Participant

    Hi @robin-w

    You who always help are probably an angel.

    I followed your advice and modified the code
    However, thumbnails are displayed on all forums topic….

    Thanks~

    @purityboy83

    Participant

    Hi @robin-w

    echo (bbp_topic_permalink().'">

    Is there a way to set forum_id here?

    Thanks for always help

    @robin-w

    Moderator

    oops sorry should read

    $forum_id = bbp_get_topic_forum_id()
            if((!bee_catch_image() == '') && $forum_id == '12345'){

    == being compare

    @purityboy83

    Participant

    Hi @robin-w

    Sorry, can I check more?

    @robin-w

    Moderator

    the one above should work – I changed

    $forum_id = '12345'
    to
    $forum_id == '12345'

    @purityboy83

    Participant

    hi~!

    Are you a genius?
    When I changed it to “$forum_id == ‘12345”, only 1 forum thumbnail was created.

    Thanks~!!!!!!

    @robin-w

    Moderator

    Great – glad you are fixed 🙂

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