Cutoff or Limit introtext characters

Need help with the Administration of your Joomla! 1.5 site? This is the spot for you.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
Mello
Joomla! Intern
Joomla! Intern
Posts: 98
Joined: Fri Jan 25, 2008 8:12 am
Location: Kuwait
Contact:

Cutoff or Limit introtext characters

Post by Mello » Sat Jul 19, 2008 5:52 pm

Hey everybody,

I was searching for this for couple of days till now
and I think I got a solution to place a character count to your intro text so that if you want to make your cat. or section in blog style so it will be more

for category layout:

open :
\components\com_content\views\category\tmpl\blog_item.php

search for :

Code: Select all

<?php echo $this->item->text; ?>
replace it with:

Code: Select all

<?php
$limit =100;
if (strlen($this->item->text) > $limit) {
echo (substr($this->item->text, 0, $limit)) . " ... ";
}
else {
echo $this->item->text;
}
?>
for frontpage:
open: \components\com_content\views\frontpage\tmpl\default_item.php

search for :

Code: Select all

<?php echo $this->item->text; ?>
replace it with:

Code: Select all

<?php
$limit =100;
if (strlen($this->item->text) > $limit) {
echo (substr($this->item->text, 0, $limit)) . " ... ";
}
else {
echo $this->item->text;
}
?>
and so on
i hope I was helpful and I'd be glad if there is any comment or a correction for this code :)

Thanks Joomla
Mestslm Rady Be Tab3ek, 3sfor Fe El-7elm Masaknk :: Me7tar 3la Shat Shafayfk, Dh 3tor El Koon Men Ward
Rosheha Nasyeny Meen ANA!
My Hosting Company : http://www.sz4h.com

User avatar
dextercowley
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3286
Joined: Sun Apr 06, 2008 4:44 am
Location: Seattle, WA, USA

Re: Cutoff or Limit introtext characters

Post by dextercowley » Sun Jul 20, 2008 12:07 am

Hi. Thanks for posting this. You could also probably do this as a template override so you didn't have to modify the core files. It would work the same, but you make copies of these files and put them into new template override folders. That way it's easier to maintain. For example, you don't lose your modifications after an upgrade, so to version 1.5.5.

You can read about template overrides here: http://docs.joomla.org/How_to_override_ ... omla!_core.

Mark
Mark Dexter
"Well...how did I get here?"

Mello
Joomla! Intern
Joomla! Intern
Posts: 98
Joined: Fri Jan 25, 2008 8:12 am
Location: Kuwait
Contact:

Re: Cutoff or Limit introtext characters

Post by Mello » Sun Jul 20, 2008 11:59 am

thanks but can u place the code so can it will be useful for everybody around here
cause I'm a newbie on template override
It's been a while since I come here and I think there is many things I passed around here

and thanks for your replay by the way
Mestslm Rady Be Tab3ek, 3sfor Fe El-7elm Masaknk :: Me7tar 3la Shat Shafayfk, Dh 3tor El Koon Men Ward
Rosheha Nasyeny Meen ANA!
My Hosting Company : http://www.sz4h.com

User avatar
dextercowley
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3286
Joined: Sun Apr 06, 2008 4:44 am
Location: Seattle, WA, USA

Re: Cutoff or Limit introtext characters

Post by dextercowley » Sun Jul 20, 2008 1:56 pm

Hi. There is no special code for template overrides. It just involves putting the modified Joomla! core file in a special directory that is template specific. That way the normal core file is not modified. The modified file is used if it is found. Mark
Mark Dexter
"Well...how did I get here?"

Mello
Joomla! Intern
Joomla! Intern
Posts: 98
Joined: Fri Jan 25, 2008 8:12 am
Location: Kuwait
Contact:

Re: Cutoff or Limit introtext characters

Post by Mello » Sun Jul 27, 2008 11:35 am

dextercowley wrote:Hi. There is no special code for template overrides. It just involves putting the modified Joomla! core file in a special directory that is template specific. That way the normal core file is not modified. The modified file is used if it is found. Mark
is this right mr. mark?
html.zip
You do not have the required permissions to view the files attached to this post.
Mestslm Rady Be Tab3ek, 3sfor Fe El-7elm Masaknk :: Me7tar 3la Shat Shafayfk, Dh 3tor El Koon Men Ward
Rosheha Nasyeny Meen ANA!
My Hosting Company : http://www.sz4h.com

User avatar
dextercowley
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3286
Joined: Sun Apr 06, 2008 4:44 am
Location: Seattle, WA, USA

Re: Cutoff or Limit introtext characters

Post by dextercowley » Sun Jul 27, 2008 2:46 pm

Hi. I haven't tested the actual code, but the folder structure looks correct to me. The download zip file creates an "html" folder with subfolders. You would place this folder under your template folder, for example "<joomla! home>/templates/rhuk_milkyway/html/...". Thanks for posting this file. If anyone gets a chance to try this, please post back. Mark
Mark Dexter
"Well...how did I get here?"

chas
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 178
Joined: Thu Feb 02, 2006 9:45 am

Re: Cutoff or Limit introtext characters

Post by chas » Wed Aug 06, 2008 2:48 am

hi it works but it wont display tags???

{audio}{/audio}

edit: how to make it add the read more button? :D

Mello
Joomla! Intern
Joomla! Intern
Posts: 98
Joined: Fri Jan 25, 2008 8:12 am
Location: Kuwait
Contact:

Re: Cutoff or Limit introtext characters

Post by Mello » Wed Aug 06, 2008 8:38 pm

chas wrote:hi it works but it wont display tags???

{audio}{/audio}

edit: how to make it add the read more button? :D
try not to add the template override files and do the modification above
cause this display tags is not default by the Joomla core I thing it's a plugin so may be it got it own modification and u override them by adding mine
Mestslm Rady Be Tab3ek, 3sfor Fe El-7elm Masaknk :: Me7tar 3la Shat Shafayfk, Dh 3tor El Koon Men Ward
Rosheha Nasyeny Meen ANA!
My Hosting Company : http://www.sz4h.com

chas
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 178
Joined: Thu Feb 02, 2006 9:45 am

Re: Cutoff or Limit introtext characters

Post by chas » Thu Aug 07, 2008 12:37 am

hi thanks i will give it a try.... how do i add a link to the articles from the title?? cheers

Mello
Joomla! Intern
Joomla! Intern
Posts: 98
Joined: Fri Jan 25, 2008 8:12 am
Location: Kuwait
Contact:

Re: Cutoff or Limit introtext characters

Post by Mello » Thu Aug 07, 2008 8:32 pm

chas wrote:hi thanks i will give it a try.... how do i add a link to the articles from the title?? cheers
If u mean like this?

Code: Select all

<a href="Link to the article">Title of the article</a>
then it's too easy to say
for all the articles u can do it from
Article manager ==> Parameters ==> Title Linkable "Check Yes" ==> Save
for an exact article visit article modification page from the backend
See the left parameters and check yes for "Title Linkable"

for more docs about dealing with the backend control visit this link
http://docs.joomla.org/Beginners
http://docs.joomla.org/Administration_FAQs
Mestslm Rady Be Tab3ek, 3sfor Fe El-7elm Masaknk :: Me7tar 3la Shat Shafayfk, Dh 3tor El Koon Men Ward
Rosheha Nasyeny Meen ANA!
My Hosting Company : http://www.sz4h.com

chas
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 178
Joined: Thu Feb 02, 2006 9:45 am

Re: Cutoff or Limit introtext characters

Post by chas » Thu Aug 07, 2008 11:37 pm

hi thanks, joomla has some funny quirks, but the more useful features it doesnt have

anyways, your code strips the the tags......when used directly on the mod

http://beautifulsmiles4life.com/

the first article has no music player

is there another way?

Mello
Joomla! Intern
Joomla! Intern
Posts: 98
Joined: Fri Jan 25, 2008 8:12 am
Location: Kuwait
Contact:

Re: Cutoff or Limit introtext characters

Post by Mello » Fri Aug 08, 2008 9:14 pm

chas wrote:hi thanks, joomla has some funny quirks, but the more useful features it doesnt have

anyways, your code strips the the tags......when used directly on the mod

http://beautifulsmiles4life.com/

the first article has no music player

is there another way?
Try to change this

Code: Select all

$limit =100;
to this

Code: Select all

$limit =350;
for example to check may be it cut down from the middle of the audio plugin code and so it doesn't appear
Mestslm Rady Be Tab3ek, 3sfor Fe El-7elm Masaknk :: Me7tar 3la Shat Shafayfk, Dh 3tor El Koon Men Ward
Rosheha Nasyeny Meen ANA!
My Hosting Company : http://www.sz4h.com

chas
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 178
Joined: Thu Feb 02, 2006 9:45 am

Re: Cutoff or Limit introtext characters

Post by chas » Tue Aug 12, 2008 12:30 pm

Code: Select all

<?php
$limit =200;
if (strlen($this->item->text) > $limit) {
echo (substr($this->item->text, 0, $limit)) . ' <a href="'. ($this->item->readmore_link) .'"> ... </a> ';
}
else {
echo $this->item->text;
}
?>

how do i add article link to the "..."

jack_t
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Sep 05, 2007 12:02 am

Re: Cutoff or Limit introtext characters

Post by jack_t » Thu Aug 28, 2008 2:06 am

i need the same thing for my home page (JOOMLA 1.0 ). to have any option for limit intro text length.
because you have only an small place for intro text in frontpage.
i also could add 2 options in frontpage.xml to enable it for admin.
but i could not find any solution in PHP part.
if i change anything in content.php.html everything will change in all pages not only for frontpage.

thanks in advance.

mrd5
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sat Mar 01, 2008 11:21 pm

Re: Cutoff or Limit introtext characters

Post by mrd5 » Mon Sep 29, 2008 1:59 am

Hi,

I would love to integrate this into my site, but don't have much PHP experience.

How would the code be written to work with html/mod_newsflash/vert.php which I am using to display FAQs (they can get pretty long so it would be great to limit the length and have the read more button lead to the FAQ page).

This is the existing code for vert.php - I'm struggling to figure out how I would combine this with your code.

Code: Select all

<?php // @version $Id: vert.php 8796 2007-09-09 15:46:34Z jinx $
defined('_JEXEC') or die('Restricted access');
?>

<?php if (count($list) == 1) :
	$item = $list[0];
	modNewsFlashHelper::renderItem($item, $params, $access);
elseif (count($list) > 1) : ?>
<ul class="vert<?php echo $params->get('moduleclass_sfx'); ?>">
	<?php foreach ($list as $item) : ?>
	<li>
		<?php modNewsFlashHelper::renderItem($item, $params, $access); ?>
	</li>
	<?php endforeach; ?>
</ul>
<?php endif;
Thanks a bunch!

Ropet4
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Sun Sep 18, 2005 11:59 am
Location: Copenhagen, Denmark

Re: Cutoff or Limit introtext characters

Post by Ropet4 » Fri Oct 03, 2008 12:34 pm

I'm having the exact same problem with mod_NewsFlash! I want to be able to limit the characters.

Mello
Joomla! Intern
Joomla! Intern
Posts: 98
Joined: Fri Jan 25, 2008 8:12 am
Location: Kuwait
Contact:

Re: Cutoff or Limit introtext characters

Post by Mello » Mon Nov 03, 2008 11:57 pm

Ropet4 wrote:I'm having the exact same problem with mod_NewsFlash! I want to be able to limit the characters.
Sorry For delay response I was away for couple of months busy starting my hosting company

so could u please send me the module here to check it and answer u back?
Mestslm Rady Be Tab3ek, 3sfor Fe El-7elm Masaknk :: Me7tar 3la Shat Shafayfk, Dh 3tor El Koon Men Ward
Rosheha Nasyeny Meen ANA!
My Hosting Company : http://www.sz4h.com

User avatar
youbusy
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Mon Oct 20, 2008 3:17 pm

Re: Cutoff or Limit introtext characters

Post by youbusy » Thu Nov 20, 2008 11:30 pm

Is there any way to do this to the main text (not the introtext) on the frontpage or section article listing page?

Thanks in advance.

Mello
Joomla! Intern
Joomla! Intern
Posts: 98
Joined: Fri Jan 25, 2008 8:12 am
Location: Kuwait
Contact:

Re: Cutoff or Limit introtext characters

Post by Mello » Fri Nov 21, 2008 10:35 am

youbusy wrote:Is there any way to do this to the main text (not the introtext) on the frontpage or section article listing page?

Thanks in advance.
I think it can be done

That's my basic code as it mention above

Code: Select all

<?php
$limit =200;
if (strlen(^$this->item->text^) > $limit) {
echo (substr(^$this->item->text^, 0, $limit)) . ' <a href="'. ($this->item->readmore_link) .'"> ... </a> ';
}
else {
echo ^$this->item->text^;
}
?>
^Text^ between the up character is the original Intro Text Code

so you can take a look at the files in html directory
see what ever you want to cut off and add this code with replacing the intro text code with the other something ;)
and don't forget to remove any ^ from the code it's just right there to help u figure it out

Hope I was clear right here
Mestslm Rady Be Tab3ek, 3sfor Fe El-7elm Masaknk :: Me7tar 3la Shat Shafayfk, Dh 3tor El Koon Men Ward
Rosheha Nasyeny Meen ANA!
My Hosting Company : http://www.sz4h.com

User avatar
youbusy
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Mon Oct 20, 2008 3:17 pm

Re: Cutoff or Limit introtext characters

Post by youbusy » Fri Nov 21, 2008 1:51 pm

Thank you, Mello. I was tired last night and didn't read through your original instructions very well. I made the change and it works great.

One more question: How do I change the following to force "readmore" and "comments" links to show on every entry on this output:

Code: Select all

<?php if ($this->item->params->get('show_readmore') && $this->item->readmore) : ?>
<tr>
	<td  colspan="2">
		<a href="<?php echo $this->item->readmore_link; ?>" class="readon<?php echo $this->item->params->get('pageclass_sfx'); ?>">
			<?php if ($this->item->readmore_register) :
				echo JText::_('Register to read more...');
			elseif ($readmore = $this->item->params->get('readmore')) :
				echo $readmore;
			else :
				echo JText::sprintf('Read more...');
			endif; ?>
Again, that you very much for this info.

Best regards,

Mello
Joomla! Intern
Joomla! Intern
Posts: 98
Joined: Fri Jan 25, 2008 8:12 am
Location: Kuwait
Contact:

Re: Cutoff or Limit introtext characters

Post by Mello » Sat Nov 22, 2008 3:49 pm

I didn't get u by the way
the code u just entered is for showing "Read more ... " dialogue in the end of every intro page

If you would like to disable it I think you don't have to play with da code u just can go to you backend admin and from the article manager you can set it in the parameter options at the left side

there is an option says enable read me link

you can disable it but make sure that you make da article title is links to the article from the same page at the top

otherwise the visitors will unable to see the article
just they will see the intro text

I hope I was clear again and if you mean something else around here
don't hesitate to ask
Mestslm Rady Be Tab3ek, 3sfor Fe El-7elm Masaknk :: Me7tar 3la Shat Shafayfk, Dh 3tor El Koon Men Ward
Rosheha Nasyeny Meen ANA!
My Hosting Company : http://www.sz4h.com

User avatar
Adam Eterno
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 120
Joined: Fri Aug 19, 2005 11:20 pm
Location: Ireland

Re: Cutoff or Limit introtext characters

Post by Adam Eterno » Mon Apr 27, 2009 5:26 pm

Works perfectly. Thanks for taking the time to post all this

alaamac
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Oct 08, 2007 8:50 pm

Re: Cutoff or Limit introtext characters

Post by alaamac » Tue May 12, 2009 11:23 am

thanks alot

alaamac
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Oct 08, 2007 8:50 pm

Re: Cutoff or Limit introtext characters

Post by alaamac » Tue May 12, 2009 11:23 am

thanks alot

medy
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Thu Jan 19, 2006 11:07 am

Re: Cutoff or Limit introtext characters

Post by medy » Fri Jun 19, 2009 2:07 pm

Hi all,

I am currently using next code do display my category and section articles:

Code: Select all

<?php $thistext = $this->item->fulltext; ?>

<?php preg_match('/<img ([^>]*?)>/', $this->item->fulltext, $match); ?>
It shows article full text with linkable image.

Now I am trying to combine this code with code posted here, so that articles would still be displayed with linked image but also with cutoff text.

Code: Select all

<?php
$limit =200;
if (strlen($this->item->text) > $limit) {
echo (substr($this->item->text, 0, $limit)) . ' <a href="'. ($this->item->readmore_link) .'"> ... </a> ';
}
else {
echo $this->item->text;
}
?>
So far i haven't had any success besides getting constant php errors...So i decided to post this question and i hope somebody can give me some piece of advice how to merge this two codes?

mykb93
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Sat Feb 09, 2008 1:22 pm

Re: Cutoff or Limit introtext characters

Post by mykb93 » Mon Jul 06, 2009 8:07 pm

Hey everybody,

I was searching for this for couple of days till now
and I think I got a solution to place a character count to your intro text so that if you want to make your cat. or section in blog style so it will be more
Mello wrote:for category layout:

open :
\components\com_content\views\category\tmpl\blog_item.php

search for :

Code: Select all

<?php echo $this->item->text; ?>
replace it with:

Code: Select all

<?php
$limit =100;
if (strlen($this->item->text) > $limit) {
echo (substr($this->item->text, 0, $limit)) . " ... ";
}
else {
echo $this->item->text;
}
?>
I have tried this and I keep getting cut off with like 2 two 3 words. I am using Joomla 1.5.8 (i know I need to upgrade). Can anyone help me with this please?

Thanks!
You do not have the required permissions to view the files attached to this post.

Mello
Joomla! Intern
Joomla! Intern
Posts: 98
Joined: Fri Jan 25, 2008 8:12 am
Location: Kuwait
Contact:

Re: Cutoff or Limit introtext characters

Post by Mello » Mon Jul 06, 2009 11:43 pm

just don't format your text

use css formating instead

cause the limiting includes the html code that may be long or few between the beginning words
Mestslm Rady Be Tab3ek, 3sfor Fe El-7elm Masaknk :: Me7tar 3la Shat Shafayfk, Dh 3tor El Koon Men Ward
Rosheha Nasyeny Meen ANA!
My Hosting Company : http://www.sz4h.com

mykb93
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Sat Feb 09, 2008 1:22 pm

Re: Cutoff or Limit introtext characters

Post by mykb93 » Tue Jul 07, 2009 2:07 pm

Mello wrote:just don't format your text

use css formating instead

cause the limiting includes the html code that may be long or few between the beginning words

I did use the CSS to fomat the text. The html in the edit page only has a <p> at the begining of the first paragraph and that is it, so I do not think that is the issue.

mykb93
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Sat Feb 09, 2008 1:22 pm

Re: Cutoff or Limit introtext characters

Post by mykb93 » Tue Jul 07, 2009 7:09 pm

Ok so I am new at this...

I figured out my own problem. I downloaded a plugin for auto read more. I thought I turned that off and the installed one on. Well it was just the opposite.

Everything is fine now, nothing to see here...

Thanks for all the help everyone!!

doonee
Joomla! Intern
Joomla! Intern
Posts: 55
Joined: Wed Apr 18, 2007 8:51 pm

Re: Cutoff or Limit introtext characters

Post by doonee » Thu Jun 03, 2010 3:31 pm

hi

the code works great over here, many thanks !!
however, ive been wondering if this can be done while leaving the "leading" article alone, ie. showing full text for the leading article while only limiting the chars of the intos that follow up....

best regards
dee


Locked

Return to “Administration 1.5”