Jump to content


Photo
AnyLoop

Ellipsis on AnyLoop Compact Post Titles



Best Answer dario , 19 July 2013 - 07:21 PM

So, I solved limiting the ellipsis to AnyLoop myself!  :D 
 

 
// LIMITS THE POST TITLE TO 30 CHARACTERS IF NOT IN THE POST LOOP //
function titlelimitchar($title){
	if(!in_the_loop() && !is_page() && strlen($title) > 30 && !(is_single()) && !(is_page())){
		$title = mb_substr($title,0,30) . "…";
	}
	return $title;
}

add_filter( 'the_title', 'titlelimitchar' );
Go to the full post


  • Please log in to reply
2 replies to this topic

#1 dario

dario

    Super Member

  • Members

  • 115 posts
  • LocationMinneapolis
  • Framework Version:2.4.4
  • Country: Country Flag

Posted 17 July 2013 - 06:57 PM

I'm using AnyLoop in a box (one in each box as is shown in the attached image), to display the most recent posts from a specific category.

The post titles are not styled as I prefer and I am trying to truncate them to overflow breakpoint. As I understand it, text-overflow: ellipsis; needs a width setting to work.

 

How can I achieve this while still maintaining the responsive nature of the page?

 

 

Attached Files



#2 dario

dario

    Super Member

  • Members

  • 115 posts
  • LocationMinneapolis
  • Framework Version:2.4.4
  • Country: Country Flag

Posted 19 July 2013 - 02:47 PM

Well, afters hours of searching and experimenting I finally got this work work (sort of):

 
// LIMITS THE POST TITLE TO 30 CHARACTERS //
function titlelimitchar($title){
	if(strlen($title) > 30 && !(is_single()) && !(is_page())){
		$title = mb_substr($title,0,30) . "…";
	}
	return $title;
}
add_filter( 'the_title', 'titlelimitchar' );

Of course that code affects all post titles on the home/blog page, not just those in an AnyLoop.

 

Does AnyOne have ideas on:

  • how to restrict this to AnyLoop?
  • refigure the code to back up to the beginning of the word being truncated and place the ellipsis there instead of cutting off the word?


#3 dario

dario

    Super Member

  • Members

  • 115 posts
  • LocationMinneapolis
  • Framework Version:2.4.4
  • Country: Country Flag

Posted 19 July 2013 - 07:21 PM   Best Answer

So, I solved limiting the ellipsis to AnyLoop myself!  :D 
 

 
// LIMITS THE POST TITLE TO 30 CHARACTERS IF NOT IN THE POST LOOP //
function titlelimitchar($title){
	if(!in_the_loop() && !is_page() && strlen($title) > 30 && !(is_single()) && !(is_page())){
		$title = mb_substr($title,0,30) . "…";
	}
	return $title;
}

add_filter( 'the_title', 'titlelimitchar' );

  • beardedavenger likes this





Also tagged with one or more of these keywords: AnyLoop