Recent Topics

Display only first paragraph of each article on link blog

Started by on May 27, 2007 – Contents updated: May 27, 2007

May 27, 2007 17:25    

I have a multiuser blog and I would like to display only the first paragraph of each article (or cut the article off after a certain number of words). I know that the author can use the M! button when writing the post but I don't want the "More" button to be displayed when viewing that post on the author's blog, I just want the article to "cut off" after a certain length on the link blog page.

I wonder there's a way to count the number of words or characters in the post and then only omit everything else when displaying on the link blog page. Any assistance is greatly appreciated.

May 31, 2007 06:48

Replace

$Item->content();

in your skins main.php file with

echo $Item->get_content(
/*mixed $disppage =*/ '#',
/*mixed $dispmore =*/ '#',
/*string $more_link_text =*/ '#',
/*string $more_anchor =*/ '#',
/*string $before_more =*/ '#',
/*string $after_more =*/ '#',
/*string $format =*/ 'htmlbody',
/*integer $cut =*/ 200 /* robrockley, this is what you change, it's the amount of words you want */
);

May 31, 2007 08:51

One little problem: $cut doesn't count if $format isn't 'xml'. See http://doc.b2evolution.net/v-1-9/__filesource/fsource_evocore__blogsincMODELitems_item.class.php.html#a1220 and http://doc.b2evolution.net/v-1-10/__filesource/fsource_evocore__blogsincMODELitems_item.class.php.html#a1221 for the line of code that shows this to be the situation. I do not know what will happen if you make the format be xml. Probably won't show images or have links be links?

robrockley what do you mean by "on the link blog page"? You can get rid of the text that shows up for both "read more" and whatever it says on the permalink page, but first it'll help to know what you're asking about. Got a link where we can see what you don't want?

May 31, 2007 13:58

Hrmm, ok, then i have no clue.

Jun 01, 2007 00:05

Thank you both (Balupton and EdB) for your feedback. I have a multiuser blog. What I'd like to do is display the first 150 words of each post on the 'Blog All' page but display the full (non-truncated) post on the user's blog page as it would normally appear. I'd like to display an ellipsis (...) after the first 150 words.

I did look at the technical documention for the content() and get_content() functions. If $format is passed as 'xml' to the content() function, the post text does get get off at whatever value is specified for $cut.

I'm presuming that the code within the get_content() function that does this when $format = 'xml' is the following:

if( ($format == 'xml') && $cut )

        { // Let's cut this down...

            $blah = explode(' ', $output);

            if (count($blah) > $cut)

            {

                $excerpt = '';

                for ($i=0; $i<$cut; $i++)

                {

                    $excerpt .= $blah[$i].' ';

                }

                $output = $excerpt.'...';

            }

        }

If I changed that to:

if( ($format == 'xml' || $format == 'htmlbody') && $cut )

and set $cut to 150 on the Blog All _main.php file then perhaps this would accomplish my goal. I guess there's one one way to find out ;)

Jun 01, 2007 01:48

Yup. The thing is if word 150 is the src part of an img tag or the href part of a link it'll be worse than a dangling participle. Whatever that is. Meaning I don't think it'll finish the tag meaning it'll be b-a-d for your visitors.

But if you try it you'll be the expert on what happens!

Jun 01, 2007 07:06

The best bet would just be to output unformatted plain text, and if that still outputs the '

' etc then do a regex or something to remove those.

I would have another crack at it maybe tomorrow or sunday.


Form is loading...

Build your own website! – This forum is powered by b2evolution CMS, a complete engine for your website.