• 0
Sign in to follow this  
Followers 0

Change excerpt length for post content feature slides

Question

Posted · Report post

I have created a page that uses Features to show certain posts in a carousels fashion. The idea is that large monitors are set up in different departments, showing slides of blog posts of particular interest to them. Since the slides need to have the same content as the blog posts, it would be unnatural to use feature sets, however neat they are. Simply allowing post authors to check or uncheck a category in the post editor, and have their posts pop in and out of the monitors seems a user friendly approach. Everything is working wonderfully out of the box with a few css tweaks and a bit of javascript to keep the show automatically in-/excluding updated blog pages. Fairly few icy cows here. The problem is that the excerpt length cannot be changed with post content, leaving the slide shows with a meager 30 words and a More button. The global setting has no effect, btw. Can I change this excerpt length somehow? p.s. The fact that the feature slider only accepts one post category will become an issue at some point but we can deal with that later.

Share this post


Link to post
Share on other sites

12 answers to this question

  • 0

Posted · Report post

You need to create a filter in functions.php (in PageLines Customize plugin). Here's the snippet to add: [code]function custom_excerpt_length( $length ) { if( is_category() ) { return 100; } return $length; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );[/code] As for the category... you can apply one category to a feature set. If you want to have different author pages with different sliders per category, apply the category to a feature set.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

I tried doing this but it doesn't work. I entered this in the functions.php... [code]function custom_excerpt_length( $length ) { if( is_page() ) { $length = 9999; } echo $length; return $length; } add_filter ( 'excerpt_length', 'custom_excerpt_length', 999 );[/code] ...to have it only activate on a singular page, which indeed it does. The echo shows that at the front page the $length is 45 (as set in the Pagelines preferences) and at the Feature page it returns 9999 as expected. The excerpt, however, is unaffected. Letting the filter set $length regardless of page type, does affect the frontpage but not the Feature page. It appears that the Feature section disregards the excerpt_length setting altogether.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

I'm not an expert at PHP, unfortunately, but I think since Feature section is this one section on the page, the code would need to be tweaked to work for it.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Catrina, you are right that it needs tweaking to work only for the Feature section and not affect other parts, but for testing purposes I am letting it affect all it can and the problem there is, that the Feature section does not appear to query the[i] excerpt_length[/i] method but uses something else and thus the solution doesn't work. The method is being called, no doubt about that, for the [i]echo [/i]statement is being executed. The return value, however, is not being used.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Is there some reason why the code I provided earlier, which was correct as is, was edited in your application of it? We tested it as provided and it worked. Was there some compelling necessity to make it not work? Look at your edit. You've set the key number to 9999 with the change to 999. That's set up that the length is 9999, but that it has to change that to 999. LESS, not MORE Of course that's not going to work. I understand the desire to be creative, but if you're not expert in it, is it smart to change code?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

The change shown here was to show the simple [i]echo[/i] statement - not showcase my coding skills. The code you provided worked *with post excerpts* but not with the excerpt length on Features. *That* is why I changed it. To rephrase my original question... I have a Feature set up out of the box. Works splendidly. The Feature shows an excerpt of the blog post next to the picture. This excerpt length does not change. I am not talking about excerpts on the frontpage or anywhere else, where indeed your code *does* work. I will check the code tomorrow when I am back in the office, to see where exactly the cropping takes place.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

This is what the Feature section does [sections/features/section.php @ line 448]... [code]apply_filters( 'pagelines_feature_output', custom_trim_excerpt( get_the_excerpt(), '30' ) )[/code]

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

This works (and has in fact been tested)... [code]function custom_excerpt_length( $length ) { if( is_page() ) { $length = 9999; } return $length; } add_filter ( 'excerpt_length', 'custom_excerpt_length' ); function custom_trim_excerpt($text, $length) { if ( !is_page() ) { $text = parent::custom_trim_excerpt($text, $length); } return $text; }[/code] ...but relies on excerpts not being used elsewhere inside Pages which is true in my case. Instead of is_page() it should check for being on a Feature page. Even better, have a setting on the Feature metapage.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Hi Thomas, Has you issue been resolved or do you require further assistance?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

The problem at hand is dealt with but I consider the originally presented solution inadequate and the reply to my remarks to that effect inappropriate in so much as the fault was not in my changes to the example code but an oversight within the Feature section code (which you can easily verify by looking at your builds). In other words, the fault of Pagelines and not me. In this light remarks to my level of expertise is off the mark, which indeed any such remarks always are. Having [b]paid[/b] for this product doesn't exactly help me accept this type of behaviour.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Hi, In my opinion this isn't an issue with PageLines, this is simply the way our feature slider works. If you do not like the feature slider functionality, you're free to use create your very own slider or use another. I'm not quite sure what behaviour you're referring to, can you go into greater detail please.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

[quote]In my opinion this isn't an issue with PageLines[/quote] I completely understand. That is not, however, the impression I get when receiving a reply saying that what I was looking for is in fact [b]doable[/b] and at the same time was presented with a solution. The solution didn't work (which is quite okay) and I commented on that, quite civilized I might add. The [b]behaviour[/b] I am referring to, is the reply I was then met with... [quote]Is there some reason why the code I provided earlier, which was correct as is, was edited in your application of it? We tested it as provided and it worked. Was there some compelling necessity to make it not work? Look at your edit. You've set the key number to 9999 with the change to 999. That's set up that the length is 9999, but that it has to change that to 999. LESS, not MORE Of course that's not going to work. I understand the desire to be creative, but if you're not expert in it, is it smart to change code?[/quote] I then went on to resolve the problem myself and did so. End of story. The Pagelines Frameworks is a brillant product and helped me save time on an internal project. To reiterate: [b]1)[/b] I ask a simple question [b]2)[/b] I get a perfectly good answer [b]3)[/b] I ask why it doesn't work as expected [b]4)[/b] I am pretty much told that it fails because I am stupid [b]5)[/b] I do what I should have done to begin with and browse the Feature Section code myself and upon realising that 2) is not even close, resolve the issue in a somewhat different manner and must then conclude that 4) is an invalid answer (not that it was acceptable in the first place)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0