Category Blog Layout character/word limit

Your code modifications and patches you want to share with others.
Locked
verzosa
Joomla! Intern
Joomla! Intern
Posts: 52
Joined: Fri Jul 17, 2009 5:05 pm
Contact:

Category Blog Layout character/word limit

Post by verzosa » Fri Apr 09, 2010 5:58 pm

I did some serching but found only old post. What i want to achieve is to automatically limit the character/word count when displaying Category Blog Layout. Is there a plugin or hack to do this?

Thanks in advance
http://detoxstudio.com - Inspiring Visual Communication, Web design and Print.

User avatar
wwtn
Joomla! Guru
Joomla! Guru
Posts: 714
Joined: Sun Oct 30, 2005 3:05 pm
Location: USA
Contact:

Re: Category Blog Layout character/word limit

Post by wwtn » Fri Apr 09, 2010 6:28 pm

While I don't know off hand of any such extension or hack, there is a simple solution for what I believe you are trying to achieve.

When you create a new content item (article) insert a "read more" after the first x number of characters, words or sentences you are limiting it to. Usually you can gauge where to insert the a "read more" without having to count every character but if you need to be that precise, then there are numerous ways to auto count your copy before inserting it into Joomla!.

For an example of how this might look... Go to this URL and see how "read more" was used to put some measure of control into a Category Blog Layout:

http://www.wwtelenet.com/web-design/articles.html

While we don't bother to precisely count characters or words, as you can see, the layout is fine enough. The main thing is for the copy to read well rather than necessarily look 100% uniform.

I hope this helps you while you continue to search for some other more automated way of limiting text in your Category Blog Layout. If you ever do find something that helps out in that regard, come back to this thread and post your solution.

Warm regards,

Jeanne Sheridan
Worldwide TeleNet - Joomla! Website Design & Web Development
Cincinnati - Northern Kentucky - USA
https://www.facebook.com/wwtndesign
http://www.wwtelenet.com/about-us/why-choose-us.html

verzosa
Joomla! Intern
Joomla! Intern
Posts: 52
Joined: Fri Jul 17, 2009 5:05 pm
Contact:

Re: Category Blog Layout character/word limit

Post by verzosa » Fri Apr 09, 2010 7:39 pm

Thanks WWTn,
Actually i found one that is perfect. It's called "Alternative read more link".
http://extensions.joomla.org/extensions ... mmary/5279

The only problem now is that it strip my Heading styles as you can see here:

http://www.charicediva.eu/News-and-Events/
http://detoxstudio.com - Inspiring Visual Communication, Web design and Print.

verzosa
Joomla! Intern
Joomla! Intern
Posts: 52
Joined: Fri Jul 17, 2009 5:05 pm
Contact:

Re: Category Blog Layout character/word limit

Post by verzosa » Fri Apr 09, 2010 7:53 pm

Ok i managed to fix it. I just removed some of the lines in plugin/content/autoreadmore.php and it works for me.

Code: Select all

<?php

// Do the usual dance
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );

class plgContentAutoReadMore extends JPlugin {

 function plgContentAutoReadMore(&$subject, $params) { parent::__construct($subject, $params); }

 function onPrepareContent( &$article, &$params ) {
  if ($this->param('Developer_Mode') != 1) {
   if ($GLOBALS['option'] == 'com_myblog') {
    // We are using the com_myblog component.  Check to be sure we're on the index page.
    if (isset($_REQUEST['show'])) return;
	} elseif (JRequest :: getCmd('option') == 'com_fjrelated') {
	// FJ Related Articles
	if((!$_REQUEST['layout']=='blog') or ($_REQUEST['id'] == $article->id)) return;
    } elseif (JRequest :: getCmd('option') == 'com_content') {
    // We are using the com_content module.  Be sure that we're on the frontpage, or category blog, or section blog.
    $view=JRequest :: getCmd('view'); $layout=JRequest :: getCmd('layout');
    if(! (($view=='frontpage') || (($view=='category') && ($layout=='blog')) || (($view=='section') && ($layout=='blog'))) ) return;
    } else {
    // Whatever this is, it is unsupported.
    return;
    }
   // Be sure that this section/category/article is not one that the user wanted to exclude.
   if ($this->param('Enabled_Front_Page') == 0 and $view=='frontpage') return;
   if (in_array($article->sectionid, explode(',', $this->param('Exclude_Section_Ids')))) return;
   if (in_array($article->catid, explode(',', $this->param('Exclude_Category_Ids')))) return;
   if (in_array($article->id, explode(',', $this->param('Exclude_Article_Ids')))) return;
   }
  // How many characters are we allowed?
  $GLOBALS['AutoReadMore_Count'] = (isset($GLOBALS['AutoReadMore_Count'])) ? $GLOBALS['AutoReadMore_Count']+1 : 1;
  $params = $GLOBALS['mainframe']->getParams();
  $num_leading_articles = $params->def('num_leading_articles', 0);
  if ($GLOBALS['AutoReadMore_Count'] <= $num_leading_articles) {
   // This is a leading (full-width) article.
   $max_chars = $this->param('Leading_Max_Chars');
   } else {
   // This is not a leading article.
   $max_chars = $this->param('Max_Chars');
   }
  if (!is_numeric($max_chars)) $max_chars = 500;
  // What text are we working with?
  if ($this->param('Ignore_Existing_Read_More') == 1) {
   // Use introtext and fulltext.
   $text = $article->introtext . $article->fulltext;
   } else {
   // Use introtext only.
   $text = $article->introtext;
   if ($text == '') $text = $article->fulltext;
   }
  // Are we working with any thumbnails?
  $thumbnails = '';
  if ($this->param('Thumbnails') >= 1) {
   // Extract all images from the article.
   preg_match_all('/<img [^>]*>/i', $article->introtext . $article->fulltext, $matches); $matches = $matches[0];
   // Loop through the thumbnails.
   for ($thumbnail = 0; $thumbnail < $this->param('Thumbnails'); $thumbnail++) {
    if (!isset($matches[$thumbnail])) break;
    // Remove the image from $text
	$text = str_replace($matches[$thumbnail], '', $text);
    // See if we need to remove styling.
    if ($this->param('Thumbnails_Class') != '') {
	 // Remove style, class, width, border, and height attributes.
	 $matches[$thumbnail] = preg_replace('/(style|class|width|height|border) ?= ?[\'"][^\'"]*[\'"]/i', '', $matches[$thumbnail]);
	 // Add CSS.
	 $matches[$thumbnail] = preg_replace('@/?>$@', 'class="' . $this->param('Thumbnails_Class') . '" />', $matches[$thumbnail]);
	 }
	// Make this thumbnail a link.
	$matches[$thumbnail] = "<a href='" . JRoute::_("index.php?option=com_content&id={$article->slug}") . "'>{$matches[$thumbnail]}</a>";
	// Add to the list of thumbnails.
	$thumbnails .= $matches[$thumbnail];
	}
   }
  if (strlen(strip_tags($text)) > $max_chars) {
   if ($this->param('Strip_Formatting') == 1) {
    // First, remove all new lines
    $text = preg_replace("/\r\n|\r|\n/", "", $text);
    // Next, replace <br /> tags with \n
    $text = preg_replace("/<BR[^>]*>/i", "\n", $text);
    // Replace <p> tags with \n\n
   
    // Strip all tags
  
    // Truncate
    $text = substr($text, 0, $max_chars);
    // Pop off the last word in case it got cut in the middle
    $text = preg_replace("/[.,!?:;]? [^ ]*$/", "", $text);
    // Add ... to the end of the article.
    $text = trim($text) . "...";
    // Replace \n with <br />
    $text = str_replace("\n", "<br />", $text);
	} else {
    // Truncate
    $text = substr($text, 0, $max_chars);
    // Pop off the last word in case it got cut in the middle
    $text = preg_replace("/[.,!?:;]? [^ ]*$/", "", $text);
	// Pop off the last tag, if it got cut in the middle.
	$text = preg_replace('/<[^>]*$/', '', $text);
	// Add ... to the end of the article if the last character is a letter or a number.
    if (preg_match('/\w/', substr($text, -1))) $text = trim($text) . "...";
    // Use Tidy to repair any bad XHTML (unclosed tags etc)
	$tidy = new tidy(); $text = $tidy->repairString($text, array('show-body-only'=>true, 'output-xhtml'=>true), 'utf8');
	}
   // Add a "read more" link.
   $article->readmore = true;
   }
  // If we have thumbnails, add it to $text.
  $text = $thumbnails . $text;
  // If Developer Mode is turned on, add some stuff.
  if ($this->param('Developer_Mode') == 1) {
   $text = ''
	. '<div style="height:150px;width:100%;overflow:auto;">'
    . '<b>Developer information:</b><br /><pre>'
	. 'Developers: uncomment the next line in the code to display $GLOBALS.  If you see this message and do not know what it means, you should turn Developer_Mode off in the Auto Read More configuration.'
	 . (htmlspecialchars(print_r($GLOBALS, 1))) // by default, this is commented out for security.  Only uncomment it if you know what you are doing.
	. '</pre></div>'
    . $text
	;
   }
  // Set $article->text.
  $article->text = $text;
  }

 function param($name) {
  static $plugin, $pluginParams;
  if (!isset($plugin)) {
   $plugin =& JPluginHelper::getPlugin('content', 'AutoReadMore');
   $pluginParams = new JParameter( $plugin->params );
   }
  return $pluginParams->get($name);
  }

 }
http://detoxstudio.com - Inspiring Visual Communication, Web design and Print.

User avatar
wwtn
Joomla! Guru
Joomla! Guru
Posts: 714
Joined: Sun Oct 30, 2005 3:05 pm
Location: USA
Contact:

Re: Category Blog Layout character/word limit

Post by wwtn » Fri Apr 09, 2010 8:55 pm

Interesting... I found a link for the plugin that I believe you are referring to:

http://www.toao.net/182-automatic-read-more-in-joomla

Is this the plugin you have installed?

I didn't find that particular plugin in the Joomla! extensions section. Very interesting plugin though. I'll have to give it go with one of our client websites.

Warm regards,

Jeanne Sheridan
Worldwide TeleNet - Joomla! Website Design & Web Development
Cincinnati - Northern Kentucky - USA
https://www.facebook.com/wwtndesign
http://www.wwtelenet.com/about-us/why-choose-us.html

verzosa
Joomla! Intern
Joomla! Intern
Posts: 52
Joined: Fri Jul 17, 2009 5:05 pm
Contact:

Re: Category Blog Layout character/word limit

Post by verzosa » Fri Apr 09, 2010 9:05 pm

http://detoxstudio.com - Inspiring Visual Communication, Web design and Print.

User avatar
Jenny
Joomla! Champion
Joomla! Champion
Posts: 6238
Joined: Sun Aug 21, 2005 2:25 pm
Contact:

Re: Category Blog Layout character/word limit

Post by Jenny » Sat Apr 10, 2010 4:40 pm

wwtn wrote:Interesting... I found a link for the plugin that I believe you are referring to:

http://www.toao.net/182-automatic-read-more-in-joomla

Is this the plugin you have installed?

I didn't find that particular plugin in the Joomla! extensions section. Very interesting plugin though. I'll have to give it go with one of our client websites.

Warm regards,

Jeanne Sheridan
The plugin mentioned in your post Jeanne is also in the extension directory - http://extensions.joomla.org/extensions ... mmary/8665

It is pretty handy, especially if you have a number of content contributors to a site and want consistency.
Co-author of the Official Joomla! Book http://officialjoomlabook.com
Marpo Multimedia http://marpomultimedia.com

User avatar
nirmalgyanwali
Joomla! Intern
Joomla! Intern
Posts: 88
Joined: Mon Dec 01, 2008 11:08 am
Location: Sydney, Australia
Contact:

Re: Category Blog Layout character/word limit

Post by nirmalgyanwali » Sun Sep 12, 2010 2:09 am

I've tried this "AutoReadMore" plugin. But when i tried it in section blog layout. All text disappeared from page.
What's the problem.
I want to enable it in myblog component.
Joomla, Web design blog: http://www.nirmal.com.np
Joomla Web Developer Sydney, Australia: http://www.nirmal.com.au


Locked

Return to “Core Hacks and Patches”