Skip to:
Content
Pages
Categories
Search
Top
Bottom

add a "Featured Image" to a forum


  • simtic
    Member

    @simtic

    Hello bbpress gurus,

    First, thanks a lot for this wonderful plugin :)

    Now please forgive my French looking English…

    I’m using bbpress on a site where I’d like to show up on some template page a list of recent posts in the forum. get_posts is my friend and that’s ok.

    But I’d also like to show a nice picture of the categories in which those recent posts where posted. Well, “regular” posts on WP now can have a “Featured Image”. And I looked to add this to my forums as well.

    And I think I made it

    But not sure ^^

    Anyway

    I added this line in bbp-admin/bbp-forums.php :

    add_meta_box(‘postimagediv’, __(‘Featured Image’), ‘post_thumbnail_meta_box’, $this->post_type, ‘side’, ‘low’);

    in function attributes_metabox() (~ l.190)

    And it seems to be working.

    But as far as I can tell, there’s maybe 50% luck this code not doing some very bad things in the same time ^^

    PLease advice, if there is a better way to achieve this…

Viewing 25 replies - 1 through 25 (of 32 total)

  • sxalexander
    Member

    @sxalexander

    This is a bit late, but I think there’s another way to solve this.

    I think the most WordPress-y way to accomplish this is to add the following to your theme’s /functions.php:

    add_post_type_support('forum', array('thumbnail'));

    This will add the featured image metabox to all forums. See here for more details:

    https://codex.wordpress.org/Function_Reference/add_post_type_support

    Hello sxalexander,

    Yes, this is a much better way to do that.

    And it keeps the bbpress plugin unchanged, so it can safely be updated.

    Thanks !


    AAShepAA
    Participant

    @aashepaa

    sxalexander,

    Can you explain further how to implement this in the functions.php – please.


    AAShepAA
    Participant

    @aashepaa

    Bump.

    1. create bbpress directory in your theme directory
    2. copy there loop-single-forum.php from /wp-content/plugins/bbpress/templates/default/bbpress
    3. add wherever you wish the image to appear:
    <?php echo get_the_post_thumbnail($post_id, 'full'); ?>


    Travis
    Participant

    @tjtaylor

    I had to add another line to get this working:

    add_theme_support( 'post-thumbnails', array( 'forum' ) );
    add_post_type_support('forum', 'thumbnail');
    

    Shawn74
    Participant

    @shawn74

    Hello,
    thanks for the tip, it’s working perfectly…now i have a picture before the Forum Title…excatly what i need…

    Anyway i need to know how to edit it’s CSS style…

    I’m using Firebug and i was able to edit the CSS style for the topic’s thumbnails to get identical as the buddypress one…with a circle box as border…
    You should see here hxxp://www.thepanicroom.it/forum/forum/panics-room-forum/

    Unfortunately when i analyze the picture your code added, i have no idea on how to find a CSS line to modify…i get only html div span body etc etc

    I tried to change the class name to ‘Thumbnail’ and i got a perfect thumbnail…. i changed it to Avatar but no result…i also declred it exactly like the Buddypress do…but nothing to do, the picture come back to the default one…

    Please sorry for my really wild and bad english šŸ™‚

    Thank you so much…


    Shawn74
    Participant

    @shawn74

    P.s. the working code (at least for me) is the one posted by @aashepaa

    Thanks again…


    Shawn74
    Participant

    @shawn74

    Solved:

    I declared as Avatar then i used this code inside theme’s function php file:

    
    add_post_type_support('forum', array('thumbnail'));
    
    function ks_forum_icons() {
    	if ( 'forum' == get_post_type() ) {
    		global $post;
    	    if ( has_post_thumbnail($post->ID) )
    	    	echo get_the_post_thumbnail($post->ID,'thumbnail',array('class' => 'alignleft forum-icon'));
    	 }
    }
    add_action('bbp_theme_before_forum_title','ks_forum_icons');
    

    Then i changed the img.avatar style (hope to have not changed anithing else…)

    Source:
    http://www.kristarella.com/2013/04/bbpress-forum-icons/


    freshwater
    Participant

    @freshwater

    on her site/post she said we can control the icon size by css or add_image_size. can anyone give exact code for us? i don’t know what “name” we’re supposed to add size to in her above code.

    and / or could we see the css code exactly and i guess we put this code in our child theme?

    thank YOU!


    goldlux
    Participant

    @goldlux

    I was able to use this to add a featured image to a forum. But what we really need is to add a featured image to each topic post. I inserted the word “topic” in place of “forum” and it does not add the “featured image” field to the create new topic region of our page. We are using RTDating themes (for a non dating site) Is this based on my theme? It seemed so easy with the forum featured image. But how do we do the same with the topic?

    Thank you all for any help.


    Robkk
    Moderator

    @robkk

    @goldlux does this work?? you of course need a way to set the featured image of a topic though.

    add_post_type_support('topic', array('thumbnail'));
    
    function ks_topic_icons() {
    	if ( 'topic' == get_post_type() ) {
    		global $post;
    	    if ( has_post_thumbnail($post->ID) )
    	    	echo get_the_post_thumbnail($post->ID,'thumbnail',array('class' => 'alignleft topic-icon'));
    	 }
    }
    add_action('bbp_theme_before_topic_title','ks_topic_icons');

    Mei Ling
    Participant

    @mei-ling

    Hi Robkk,

    I have tested your code. Well I can select in the admin panel “edit topic” or “new topic” “featured image”, I select the picture…when I turn back to the topic, no picture. It doesn’t remain selected.
    I use the latest WordPress: 4.30.

    Could you help me?

    I thank you in advance

    Mei Ling


    kachan64
    Participant

    @kachan64

    	    if ( has_post_thumbnail($post->ID) )
    	    	echo get_the_post_thumbnail($post->ID,'thumbnail',array('class' => 'alignleft forum-icon'));
    	 }

    This is the styling for the featured image.

    bbp_theme_before_topic_title
    This part of the code determents where should featured image goes. You will need to check your code.


    Robkk
    Moderator

    @robkk

    @mei-ling

    Did you copy and edit the bbPress templates in your child theme heavily?? Removing the hook @kachan64 pointed out, can make the code not work.

    Also does the picture save correctly in the WordPress backend?? If you could link to a forum that should has a topic with a featured image, I can check to see if there is a CSS problem.


    Mei Ling
    Participant

    @mei-ling

    I got it! The picture is not displayed and that’s good. I want to use this feature to manage what is shared.
    Thank you

    Regards

    Mei Ling


    Robkk
    Moderator

    @robkk

    @mei-ling

    Well I did mess up the code anyway, you can copy the code I edited above to see if it works again if you want.

    -Don’t Drink and Code.


    Mei Ling
    Participant

    @mei-ling

    I’ve done it. It’s just perfect and I never drink. Thks Robkk šŸ™‚


    Herve ARNAUD
    Participant

    @herve-arnaud

    Late for @freshwater … Hope it will be usefull for someone else.

    To add and control the featured image size on forums:

    1- Add the following code to your child theme functions.php file.

    add_post_type_support('forum', array('thumbnail'));
    add_image_size('forum-category-thumbnail', 1080, 320, true);

    2- (optional) Change/rename “forum-category-thumbnail” by something more useful for you if you need.

    3- Set featured image size by changing numbers. First number is width in pixels and last is the height.

    4- (if not done yet) Create a bbpress directory in your child theme.

    5- (if not done yet) Copy the template file you want to affect from …/plugins/bbpress/template/defaut/bbpress/your_template.php to your bbpress directory.
    for example: content-single-forum.php

    6- Add the following code exactly where you want that your featured image appears in your template.

    <?php if( has_post_thumbnail() ): ?>
      <div class="entry-thumbnail"><?php the_post_thumbnail('forum-category-thumbnail') ?></div>
    <?php endif; ?>

    If you made change on point NĀ°2 remember to change “forum-category-thumbnail” by what you’ve choose.


    kingbob123
    Participant

    @kingbob123

    Got it. useful discussion.

    Here’s a slight variant that removes the need to edit your templates, you can just hook into the template in the place needed šŸ™‚

    https://gist.github.com/ntwb/8277457


    pazzaglia
    Participant

    @pazzaglia1

    How can I vary this code to include a default image for topics? I post new forum topics to facebook and at the moment they’re showing a TERRIBLE giant picture – when there are no profile pics or attachments to display. I don’t even know where it’s being pulled from.

    http://www.hippressurecooking.com/forum/

    pressure cooker forums

    Thanks!
    L


    Tenebral
    Participant

    @tenebral

    Thank you @netweb .

    I just added the permalink, title and change the size from thumbnail to 80×80:

    add_action( 'widgets_init', 'rkk_widgets_init' );
    
    add_post_type_support('forum', array('thumbnail'));
    function ks_forum_icons() {
    	if ( 'forum' == get_post_type() ) {
    		global $post;
    	    if ( has_post_thumbnail($post->ID) )
    			echo '<a href="' . get_permalink( $_post->ID ) . '" title="' . get_the_title( $_post->ID ) . '">';
    	    	echo get_the_post_thumbnail($post->ID,array(80,80),array('class' => 'alignleft forum-icon'));
    			echo '</a>';
    	 }
    }
    add_action('bbp_theme_before_forum_title','ks_forum_icons');

    šŸ™‚

    Hi,
    Just want to add that, for the people that do not want to code this, the functionality is also in the ‘bbP Toolkit’ plugin.
    Pascal.


    greathumza
    Participant

    @greathumza

    Hi guys, @netweb @casiepa

    I need your help i wanted to show latest topic in my sidebar with THUMBNAILS but the current widget i have doesn’t show latest topic with widget. I really need this as it attract more people. Your help will be highly appreciated. Thanks

    Regards

    HR

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