Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6662601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:24:25+00:00 2026-05-26T02:24:25+00:00

Below is a code snippet from the file I am working with. I will

  • 0

Below is a code snippet from the file I am working with. I will start by saying I have attempted to find out on my own many times with failure, I am not a coder but I wish I knew more. I need some help figuring out how to add a substr length to the string $forum

This function outputs the latest 5 forum topics. The problem I’m having is the topic titles are to long for where the widget is being placed, so I wanted to truncate it to max 35 characters displayed. Can you help me? I know I’m a newb!

   function sf_recent_posts_tag($limit=5, $forum=false, $user=true, $postdate=false, $listtags=true, $forumids=0, $posttime=false, $avatar=false, $size=25)
    {
        global $wpdb, $current_user, $sfvars;

        $limit = sf_esc_int($limit);
        if (empty($limit)) return;

        sf_initialise_globals($sfvars['forumid']);

        $out = '';
        $forum_ids = '';

        # are we passing forum ID's?
        if ($forumids != 0)
        {
            $flist = explode(",", $forumids);
            foreach($flist as $thisforum)
            {
                if (sf_can_view_forum($thisforum))
                {
                    $forum_ids[] = $thisforum;
                }
            }
        } else {
            # limit to viewable forums based on permissions
            if($current_user->forumadmin == false)
            {
                $allforums = sf_get_forum_memberships($current_user->ID);
                if ($allforums)
                {
                    foreach ($allforums as $thisforum)
                    {
                        if (sf_can_view_forum($thisforum->forum_id))
                        {
                            $forum_ids[] = $thisforum->forum_id;
                        }
                    }
                } else {
                    return '';
                }
            }
        }

        # get out if nothing to see
        if($current_user->forumadmin == false && empty($forum_ids)) return '';

        # create where clause based on forums that current user can view
        if ($forum_ids != '')
        {
            $where = ' AND '.SFPOSTS.".forum_id IN (" . implode(",", $forum_ids) . ") = 1 ";
        } else {
            $where = '';
        }

        $sfposts = $wpdb->get_results("SELECT DISTINCT topic_id
                                       FROM ".SFPOSTS."
                                       WHERE post_status = 0 ".$where."
                                       ORDER BY post_id DESC
                                       LIMIT ".$limit);

        if($sfposts)
        {
            foreach($sfposts as $sfpost)
            {
                $postdetails = sf_get_last_post_in_topic($sfpost->topic_id);
                $thisforum = sf_get_forum_record($postdetails->forum_id);
                $p=false;

                # Start contruction
                if($listtags) $out.="<li class='sftagli'>\n";

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

                $out.= sf_get_topic_url_newpost($thisforum->forum_slug, $sfpost->topic_id, $postdetails->post_id, $postdetails->post_index);

                if($forum)
                {
                    if ($p == false) $out.="<p class='sftagp'>";

                    $out.= __("posted in forum", "sforum").' '.sf_filter_title_display($thisforum->forum_name)."&nbsp;"."\n";
                    $p=true;
                }

                if($user)
                {
                    if($p == false) $out.="<p class='sftagp'>";
                    $poster = sf_build_name_display($postdetails->user_id, sf_filter_name_display($postdetails->display_name));
                    if(empty($poster)) $poster = sf_filter_name_display($postdetails->guest_name);
                    $out.=__("by", "sforum").' '.$poster.' '."\n";
                    $p=true;
                }

                if($postdate)
                {
                    if($p == false) $out.="<p class='sftagp'>";
                    $out.=__("on", "sforum").' '.sf_date('d', $postdetails->post_date)."\n";
                    if ($posttime)
                    {
                        $out.=' '.__("at", "sforum").' '.sf_date('t', $postdetails->post_date)."\n";
                    }
                    $p=true;
                }

                if($p) $out.="</p>\n";

                if($listtags) $out.="</li>\n";
            }
        } else {
            if($listtags) $out.="<li class='sftagli'>\n";
            $out.='<p>'.__("No Topics to Display", "sforum").'</p>'."\n";
            if($listtags) $out.="</li>\n";
        }
        echo($out);
        return;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:24:26+00:00Added an answer on May 26, 2026 at 2:24 am

    I can’t find where you get the post titles in your code, but to truncate a string to 35 chars you simply need something like $truncated = substr($title, 0, 35)

    You may find it helpful to append ‘…’ to the truncated titles:

    $truncated = substr($title, 0, 35).'...';


    EDIT:

    without seeing a lot of code that you have omitted it’s hard to say, but I suspect it’s a matter of changing

    $out.= sf_get_topic_url_newpost($thisforum->forum_slug, $sfpost->topic_id, $postdetails->post_id, $postdetails->post_index);

    to

    $out.= substr(sf_get_topic_url_newpost($thisforum->forum_slug, $sfpost->topic_id, $postdetails->post_id, $postdetails->post_index), 0, 35).'...';

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code snippet, which loads data from a CSV file into
The code below will print all of the text from the sample text file
In the code snippet below, from my jQuery setup, I need to check if
Which code snippet will give better performance? The below code segments were written in
I am using the code snippet below, however it's not working quite as I
I have a table defined (see code snippet below). How can I add a
I have the following code snippet which is working fine: ifstream NDSConfig( NDS.config )
The following is a code snippet from a struts.xml file for Struts 2. If
So i have this code, the snippet is given below. list* init(list* list1) {
I have a sample code snippet below which works just fine (I trimmed the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.