| How to Control the "Read More" on Joomla's Frontpage |
|
| Wednesday, 28 March 2007 | |
|
A simple tip today. This small Joomla code hack is designed to help those of you who have a lot of people submitting content to their site.
Everyone writes and submits in their own way, so its easy to end up with some contributors just writing a single line in the "intro" box and others entering their whole article.
With this hack, it doesn't matter. You can cut off all frontpage items with a "Read More..." after 200 words, giving your site a clean, professional look.
Inside /components/com_content/content.html.php you need to scroll down to line 520.
// displays Item Text
if( !isset( $_GET['id'] ) ){
$explded = explode( " ", $row->text, 201 ); $explded[200] = ''; //echo implode( " ", $explded ); //if( count( $explded )== 201 ) echo ' <a href='.$e['titleLink'].'">(more...)</a>'; echo ampReplace( implode( " ", $explded ) ); if( count( $explded )== 201 ) echo ' <a href="index.php?option=com_content&task=view&id='.$row->id.'&Itemid=2">(more...)</a>'; echo '<!-- '; print_r( $params ); print_r( $row ); echo '-->'; } else{ // displays Item Text echo ampReplace( $row->text );
Want longer or shorter teasers? Simply replace 200 and 201 with the number of words you'd like to see before the "Read More..." sign.
Click here to download the file.
Bookmark
Email This
Comments (22)
![]() written by Justin Whittaker, March 28, 2007
Nice little tip there! Definitely another one for my favourites.
written by pablo arias, March 28, 2007
hello!
error: pagina web: Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in W:wwwjoomlacomponentscom_contentcontent.html.php on line 1520 what I made bad? I replaced this lines line 516 with these lines: line 516 written by pablo arias, March 29, 2007
Funciona muy bien!! it works very well!
what to do so that it does the same in the option ?Blog? of menu? always been thankful written by Sir, April 06, 2007
Hi!
It doesn't work I try to insert very long intro text but I see every charcaters before "Read more" I used the file for joomla 1.0.12 written by Sir, April 07, 2007
Hi!!
The problem is that I'm developing the site in local. Moreover it would be not usefull to paste the code because is just the file you uploaded Mmmm, just a moment. Let's talk about how I tried this. I have a CATEGORY CONTENT - BLOG VIEW link in the user menu. So when I click on it I see the articles in blog mode. But the introduction text is still there and it's not cutted. I tried to delete the introtext and write it again, but nothing to do. written by pablo, April 18, 2007
el link para Joomla SEO Book esta mal! (it's wrong)
http://www.alledia.com/joomla-...milla (") what to do so that it does the same (to Control the "Read More") in the option ?Blog? of menu? gracias written by inan, May 20, 2007
its good in frontpage but how to make it available also in blog view of category main page
written by Web Design Canada, September 25, 2007
An easy way to also do this is to use the AlphaContent component. There is actually an option to choose how many words to include for the intro.
written by cha lee, November 25, 2007
but is there anyway to hack the "read more" to "click to read more about 'title'",like http://www.compassdesigns.net/
written by Tom, December 06, 2007
There's another way to do this. Instead under the content.php file. You can find where it assigns the $row->introtext for output under the method show().
Replace: $row->text = $row->introtext. ( $params->get( 'intro_only' ) ? '' : chr(13) . chr(13) . $row->fulltext); With: $words = 50; $wordCount = count(explode(" ",$row->introtext)); $words = 20 $words; // this is an estimate of how many words occupy an image tag if ($wordCountintrotext; } else { $adjustedText = implode(" ", array_slice(explode(" ",$row->introtext), 0, $words)); } $row->text = $adjustedText. ( $params->get( 'intro_only' ) ? '' : chr(13) . chr(13) . $row->fulltext); Note that I add 20 words to everything because on the site I built there's generally an image with the intro text right before the text starts, floated left. So I'm trying to get closer to the actual word count by starting off 20 deep. If there's extra tweaking needed, you can do so this way by also including in the XML file a new parameter for number of words. This can then be retrieved with the $params->get('name_of_param'); that you see all over the place.Note though that the normals params here are from the menu, you'll have to call new params I did so by putting in: $article_params = new mosParameters( $row->attribs ); ... but then you also have to go up higher to the other functions that put together the text for output (fontpage is one method, showBlogSection is another, etc.) and make sure the main sql query (and it's commented as the main sql query) includes a.attribs so the attribs field gets called for use. Yea, that's a little involved, but it's not so bad. Anyway, for simplicity you can just keep manually changing the word count in the code if you like. written by danceswithlife, December 10, 2007
How can you control the number of words displayed before the "Read more.." in other areas of a site, but not affect the front page?
For example, let's assume a site has 10 distinct sections. Each of these sections has its own section sub-menu to access that section's specifc content. Each section has an introductory page that should not be limited to 60 words, but the user submitted content (which is accessible via the submenu(s) should be limited to 60 words. I can a provide a url with an example if necessary. written by ehsan, January 28, 2008
doesn't worked
Parse error: syntax error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/goldnir/public_html/warezworldwide.com/components/com_content/content.html.php on line 3058 written by aniemeye, February 12, 2008
any thoughts on how to get it to work with joomla! 1.0.14?
written by Marsal, July 06, 2008
is tis possible to use for joomla 1.5 and what steps are needed. thanks
written by Space Zone, July 19, 2008
is there anyone know a link or article contain this modification for Joomla 1.5 versions?
...
written by Space Zone, July 20, 2008
Hi Again I made something more useful I think
For Joomla 1.0.X replace this code :
with :
just change the 100 variable to whatever you want for Joomla 1.5.X open : componentscom_contentviewscategory mpllog_item.php // for category or open : componentscom_contentviewsrontpage mpldefault_item.php // for frontpage and change : to: that's it
... written by Space Zone, July 20, 2008
Search for :
change it to : and sorry for my last comment cause I forget to add them between quota practices Write comment
|


