Maximum Characters for All intro Text on Front page, Blog pages, etc - Joomla! Forum - community, help and support


hi,

i want limit number of characters in intro text (bots?) on frontpage as
well section / category blog layouts.

i need insert " . . . " make obvious there more story items. read more link isn't enough
to prompt readers click on story title yet want intro text there.

obviously, hack or whatever needs sure show formatted story on next page.

i know can done - done in several extensions simple code, don't know place , more where.

any apprectiated.

jonathan

hi jonathan,

where put it, quite easy, although script looks bit scary @ first: \components\content\content.php, under function blogoutput. ready healthy hacking, , document did, i.e. put beginning , ending marker around code changed or inserted, because otherwise updating joomla hell of job.

you'll find if ($z < $intro) . in code block, you'd have manipulation of introtext, maybe this:

code: select all

<?php
$posintrolength = strpos($rows[$i]->attribs, "introlength=");
if ($posintrolength === false) {
  $lengthofintro = 300;
} else {
  $somechunk = substr($rows[$i]->attribs, $posintrolength + 12, 4);
  $lengthofintro = $somechunk;
}
$orig_intro = $rows[$i]->introtext;
$new_intro = str_stop($orig_intro, $lengthofintro);
$rows[$i]->introtext = $new_intro;
?>


the $lengthofintro variable can hardcoded. have done older articles. in example, put @ 300 characters.
for new or edited articles, make adjustable hack of /administrator/components/com_content/content.xml file, upon saving stores introlength variable in attribs field of jos_content table in joomla mysql database.

code: select all

      <param name="introlength" type="text" size="4" default="300" label="number of intro characters" description="number of characters of intro want show." />


there's call str_stop() function, neatly breaks intro @ space, , inserts "..." characters.

code: select all

<?php
function str_stop($string, $max_length){
   if (strlen($string) > $max_length){
       $string = substr($string, 0, $max_length);
       $pos = strrpos($string, " ");
       if($pos === false) {
               return substr($string, 0, $max_length)."...";
           }
       return substr($string, 0, $pos)."...";
   }else{
       return $string;
   }
}
?>


after having done this, shortened intro needs reinserted in $rows[] object: that's why $rows[$i]->introtext = $new_intro; there.

i can't guarantee work in case, because may have forgotten something: content.php , content.html.php "severely hacked" :) . anyway, keep me informed, , above all: put beginning , ending markers (maybe //name or something) around code change or insert: it's vital... (believe me, learnt hard way).

ludo





Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support