Support Forum

Code Customization

JA JanetBarclay
JanetBarclay
Member

We are currently using the Recent Forums Posts widget on http://www.storage-brain.com but it doesn't do quite what we want. We'd like to display an excerpt from the latest post, and I understand this can be done by editing the code, but this is beyond my level of expertise. If you can help, please email me at janet@organizedassistant.com.

Please note I am using SpamAssassin on that account, so you will need to respond to a challenge email for your message to reach me.

Thanks!

32 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

have you looked at the alternative ‘latest posts’ tag on the same wiki page (api – template tags – lists). This includes the post content already.

JA JanetBarclay
JanetBarclay
Member

I don't understand what code I need to use, or where to use it.

MP Mr Papa
Mr Papa
Member

in your wp theme file, where you want the latest posts to appear, you would put

<?php sf_latest_posts(); ?>

that assumes its in a section of the theme file where php code is not enabled… if it is, just forego the opening and closing php tags…  there are some options you can pass if you dont like the defaults… details in the wiki..

JA JanetBarclay
JanetBarclay
Member

Thank you – that got me started, but I am not seeing anything that explains how to include a short excerpt (3 lines) – it seems to be all or nothing.

MP Mr Papa
Mr Papa
Member

ah… afraid you are right… that tag is the whole content…  and the others are just the title… so you wouldnt need to edit the tag and apply a word count filter to the content…

JA JanetBarclay
JanetBarclay
Member

I really don't know PHP… how would I go about doing that?

YS Yellow Swordfish
Yellow Swordfish
Member

You can limit this through the admin options. On the Options > Global Settings panel – top right – are the RSS settings. In there you can impose a word count on the post cntent sent out via RSS. This template tag will use that to also limit the number of words shown in the tag.
Would that do the trick for you?

MP Mr Papa
Mr Papa
Member

holy cow!  completely missed that… nice catch Andy!

JA JanetBarclay
JanetBarclay
Member

Thanks – we're getting there… Now, is there any way to include an avatar the way the Recent Forums Posts widget does?

MP Mr Papa
Mr Papa
Member

hesitant to go down this road because without php and css knowledge could get messy…  you will have to edit the core code…  let us know if you want to do that… we can try to give you some untested code… then you will have to style it…

JA JanetBarclay
JanetBarclay
Member

I am comfortable with CSS and don't mind editing php code if you can tell me what to do. I'll be sure to back up first so I don't break anything. Smile

MP Mr Papa
Mr Papa
Member

shot in the dark here… find this query in the sf-template-tags-lists.php file, function sf_latest_posts():

$posts = sfdb_select('set',
            "SELECT post_id, topic_id, forum_id, post_content, post_index, ".sf_zone_datetime('post_date').",
             ".SFPOSTS.".user_id, guest_name, ".SFMEMBERS.".display_name FROM ".SFPOSTS."
             LEFT JOIN ".SFMEMBERS." ON ".SFPOSTS.".user_id = ".SFMEMBERS.".user_id
             ".$where."
             ORDER BY post_date DESC
             LIMIT ".$limit);

and change it to

$posts = sfdb_select('set',
            "SELECT post_id, topic_id, forum_id, post_content, post_index, ".sf_zone_datetime('post_date').",
             ".SFPOSTS.".user_id, guest_name, user_email, guestemail, ".SFMEMBERS.".display_name FROM ".SFPOSTS."
             LEFT JOIN ".SFMEMBERS." ON ".SFPOSTS.".user_id = ".SFMEMBERS.".user_id
             ".$where."
             ORDER BY post_date DESC
             LIMIT ".$limit);

and then where you want the avatar to display in that same function, add this:

if ($post->user_id)
            {
                $icon = 'user';
                if (sf_is_forum_admin($post->user_id)) $icon='admin';
            } else {
                $icon = 'guest';
            }
            $out.= sf_render_avatar($icon, $post->user_id, sf_filter_email_display($post->user_email), sf_filter_email_display($post->guestemail), false, $size);

again, this is completely untested…  you will probably want to style this to your liking… there are some threads in our forum about suggested styling for this in other tags that already allow an avatar…

LH Lee H
Lee H
Member

@ Mr. Papa…  if we had a Karma button I'd be clicking the heck out of it right now.

^5