Skip to:
Content
Pages
Categories
Search
Top
Bottom

add a "Featured Image" to a forum

  • 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 18 replies - 1 through 18 (of 18 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.


    Marcin Biegun
    Participant

    @biegun

    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 :)

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