Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
custom-topic
Code Customization
Avatar
JanetBarclay
Hamilton, Ontario, Canada
Member
Free Members
sp_UserOfflineSmall Offline
Sep 2, 2010 - 9:52 am
sp_QuotePost Quote

Sorry, that was a careless mistake on my part. It should in fact read:

Posted by JanetBarclay, Sep 2, 2010

Avatar
Lee H
Coastal New England (USA)
Member
Free Members
sp_UserOfflineSmall Offline
Sep 2, 2010 - 11:43 am
sp_QuotePost Quote

Thanks for the input Janice.

I tried posting your code on pastebin but it added so many blank lines to the code and it kinda freaked me out.  I've ran into problems posting bash scripts there in the past and had problems with it adding dos linebreaks.  Not sure if php would complain or not. So forgive me if I trash this thread posting here.

Here is the function that creates a new template tag:

Edit: It didn't post well here either. Too wide to access the "raw code" button. Here's a pastebin link. http://pastebin.org/799374

/*     ===================================================================================== 
 
    sf_latest_posts_truncate($limit=5, $trunhars=300, $pad="...") 
 
    displays the quicklinks dropdowns for forum list and recent topics list and trims content length if needed. 
 
    parameters: 
 
        $limit        How many items to show in the list                    number    5 
        $trunchars    How many charectors to find truncate point (will leave complete words)    number    300 
        $pad        If content needs trimming, this will be added to the end of it.        string    "..." 
 
     ===================================================================================*/ 
 
function sf_latest_posts_truncate($limit=5, $trunchars=300, $pad="...") 
{ 
    global $wpdb, $current_user, $sfvars; 
    $limit = sf_esc_int($limit); 
    if (empty($limit)) return; 
 
    sf_initialise_globals($sfvars['forumid']); 
 
    $out = ''; 
 
    $where = " WHERE ".SFPOSTS.".post_status = 0"; 
 
    # limit to viewable forums based on permissions 
    if (!$current_user->forumadmin) 
    { 
        $allforums = sf_get_forum_memberships($current_user->ID); 
        if ($allforums) 
        { 
            $forum_ids = ''; 
            foreach ($allforums as $thisforum) 
            { 
                if (sf_can_view_forum($thisforum->forum_id)) 
                { 
                    $forum_ids[] = $thisforum->forum_id; 
                } 
            } 
        } else { 
            return ''; 
        } 
 
        # create where clause based on forums that current user can view 
        if ($forum_ids != '') 
        { 
            $where .= " AND forum_id IN (" . implode(",", $forum_ids) . ") = 1"; 
        } else { 
            return ''; 
        } 
    } 
 
    $posts = $wpdb->get_results( 
            "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); 
 
    $out.='<div class="sf-latest">'; 
 
    if ($posts) { 
        foreach ($posts as $post) 
        { 
            $thisforum = sf_get_forum_record($post->forum_id); 
            $poster = sf_build_name_display($post->user_id, sf_filter_name_display($post->display_name)); 
            if (empty($poster)) $poster = sf_filter_name_display($post->guest_name); 
            $topic = sf_get_topic_record($post->topic_id); 
            $out.='<div class="sf-latest-header">'; 
            $out.='<a href="'.sf_build_url($thisforum->forum_slug, $topic->topic_slug, 0, $post->post_id, $post->post_index).'">'; 
            $out.=sf_filter_title_display($topic->topic_name).'</a>'; 
            $out.=__(' in ', "sforum"); 
            $out.='<a href="'.sf_build_url($thisforum->forum_slug, '', 1, 0).'">'.sf_get_forum_name($thisforum->forum_slug).'</a>';
            $out.='<br />Posted by '.$poster . ', ' .sf_date('d', $post->post_date); 
            $out.='</div>'; 
            $out.='<div class="sf-latest-content">'; 
            if($current_user->moderator == false && $status == 1) 
            { 
                $content = __("Post Awaiting Approval by Forum Administrator", "sforum"); 
            } else { 
                $content = addslashes($post->post_content); 
                $content = sf_filter_save_nohtml($content); 
                $content = htmlspecialchars($content, ENT_QUOTES, 'UTF-8'); 
                $content = str_replace('&', '&', $content); 
                if(strlen($content) > $trunchars) 
                { 
                    $content = substr($content, 0, $trunchars); 
                    if(false !== ($breakpoint = strrpos($content, ' '))) 
                    { 
                        $content = substr($content, 0, $breakpoint) . $pad; 
                    } 
                } 
 
                } 
            $out.=$content; 
            $out.='</div>'; 
            $out.='<br />'; 
        } 
    } else { 
        $out.='<div class="sf-latest-header">'; 
        $out.='<p>'.__("No Topics to Display", "sforum").'</p>'."\n"; 
        $out.='</div>'; 
    } 
 
    $out.='</div>'; 
 
    echo($out); 
    return; 
}

You can just put the above directly in the bottom of:

/wp-content/plugins/simple-forum/template-tags/sf-template-tags-lists.php if you wish. But you will lose it if Simple:Press is upgraded.

I'm not sure if this is proper, but it's working for me… you can rename /wp-content/plugins/simple-forum/forum/sf-pluggable.txt to sf-pluggable.php and place the function in there. It will survive upgrade and seems to work. If Steve or Andy have a better suggestion, I'd love to know about it 🙂

 

Once your function is in place you just edit your WordPress theme to include the tag where you would like it to show up.

<?php
if (function_exists('sf_latest_posts_truncate')) {
    sf_latest_posts_truncate(5, 100);
}
?>

This is set to show 5 posts, and the cut off is no more than 100 characters. Just change the numbers to your liking. You also have the option of changing what trails the cut off.  The default is three dots.

sf_latest_posts_truncate(5, 100, "...")

Just make sure there is a comma and a space after where the 100 is shown. Then add what you want between quotes.

If you put this tag in a sidebar sized container it will look pretty good as is. Otherwise you will need to add css styles to control the size.

Have fun 🙂

Avatar
JanetBarclay
Hamilton, Ontario, Canada
Member
Free Members
sp_UserOfflineSmall Offline
Sep 2, 2010 - 12:15 pm
sp_QuotePost Quote

Wow, thank you SO much!

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 649
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 618
Members: 17348
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10120
Posts: 79607