-
AuthorPosts
-
February 24, 2016 at 7:23 pm #588594
Hello
We are using portofolio items to show those in the Masonry view side by side.
Please see the attached image. As you can see, box #2 (right) is higher then box #1 (left).
The client wants to use same width + height for all images, no cropping allowed.
Please do note, that all of the images we use has the exact same size and aspect ratio.Is there any function that we can add to our theme’s child functions.php file that will simply limit the excerpt for all of the portofolio entries?
Basically if the text is 50 lettes and we need only 30, then the text is get cut after 30 letters and the “…” is added at the end.Something like this (not working for us):
add_filter(‘avf_masonry_excerpt_length’,’avia_change_masonry_excerpt_length’, 10, 1); function avia_change_masonry_excerpt_length($length) { $length = 30; return $length; }
We’ve also tried this code, with no positive result:
add_filter( 'avf_masonry_excerpt_length', 'masonry_excerpt_length'); function masonry_excerpt_length() { $excerpt = 30; return $excerpt; }
Please assist, thanks!
All the best
- This topic was modified 8 years, 8 months ago by WebVision.
February 25, 2016 at 12:50 pm #589010Please do help, we’ve tried nearly all possible solution from this forum with no success.
February 25, 2016 at 3:51 pm #589200Hey!
Do you mind creating a temporary admin login and posting it here privately so we can look into it? You are using correct hook
Regards,
YigitFebruary 25, 2016 at 3:57 pm #589203Hey!
Sure thing. Here you go.
February 26, 2016 at 9:53 am #589614Do you need any extra information from our end?
All the best
February 29, 2016 at 11:10 pm #591198Still looking for help :)
March 2, 2016 at 7:26 am #591915Hi!
Sorry for the delay. Bumping your own tickets will not help you get faster response as the tickets move to the bottom.
We are working on your ticket please wait while we update the results here soon.There are two ways you can do this
1.the CSS way
2. the jQuery wayNOTE: Use only one method for best results.
1. CSS Way
Just add the below css to Quick CSS
/* Excerpt length*/ .av-masonry-entry .av-masonry-entry-title + .av-masonry-entry-content { max-height: 34px!important; }
2. The jQuery way
We have added the below code in functions.php// Excerpt length function custom_excerpt(){ ?> <script> jQuery(window).load(function(){ jQuery('.type-portfolio').each(function() { jQuery("div.entry-content").text(function(index, currentText) { return currentText.substr(0, 84); }); }); }); </script> <?php } add_action('wp_footer', 'custom_excerpt');
Regards,
Vinay Kashyap- This reply was modified 8 years, 8 months ago by Vinay.
March 2, 2016 at 9:14 am #591962Hello Vinay
jQuery way would be the best, yes. And it does cut the text, yes.
But you’ve missed one important part of my original question: “if the text is 50 lettes and we need only 30, then the text is get cut after 30 letters and the “…” (&ellipsis;) is added at the end.”
Please do adjust the code, thank you.All the best.
March 2, 2016 at 5:13 pm #592192Hi!
we have modified and updated the code please check the site now…
To show more or less words please feel free to adjust the number 30 in linereturn currentText.substr(0, 30);
The code is in functions.php at the bottom.
// Excerpt length function custom_excerpt(){ ?> <script> jQuery(window).load(function(){ jQuery('.type-portfolio').each(function() { jQuery("div.entry-content").text(function(index, currentText) { return currentText.substr(0, 30); }); jQuery("div.entry-content").append("..."); }); }); </script> <?php } add_action('wp_footer', 'custom_excerpt');
Best regards,
Vinay KashyapMarch 2, 2016 at 5:29 pm #592202Dear Vinay
1) We would like to use &ellipsis; (…) instead of the … (please notice that the first sign is not 3 different dots, but 1 sign including 3 dots in 1 sign).
2) Some excerpts are short, some a longer. In a case where the excerpt is only 29 signs and we limit the excerpt by 30, the output looks funny – suddenly there is added additional 10 dots at the end.
Please recheck the site – I’ve now changed excerpt to 1000 so all of the excerpts has these many dots at the end.All the best.
March 2, 2016 at 9:00 pm #592293Hey!
We have replaced the 3 dots with ellipsis; (…) please check screenshot i do not see any issue what is the 10 dots at the end you mentioned? please share the link where we can inspect the element in question…
Regards,
Vinay KashyapMarch 2, 2016 at 9:11 pm #592298Dear Vinay
Please see the private link, 3rd portofolio box called “Automatic Dust Sampler (ADS)”
To get this effect, I’ve replaced 30 with 100. And since “Automatic Dust Sampler (ADS)”‘s excerpt is under 100 characters, you get the extra dots at the end.
While we talk about limiting the excerpt for the portofolio item, is it also possible to limit the title of the portofolio item (“Automatic Dust Sampler (ADS)”)? It should be possible to limit excerpt and the title independently of each other.
All the best
- This reply was modified 8 years, 8 months ago by WebVision.
March 2, 2016 at 10:32 pm #592325Hi!
Yes we can do that with the titles …
Sorry the code in function.php conflicted…. please login to your FTP and goto the child theme folder download the functions.php and remove the last block that says “// Title length” from functions.php and re-upload it or create a FTP user ID and share in private.
Best regards,
Vinay KashyapMarch 2, 2016 at 11:46 pm #592346Hey again
Sounds great!
Last block has been removed as requested.
All the best
March 3, 2016 at 9:29 am #592505Hi!
we have limited the title and excerpts however it works till 90 characters… Not sure if it’s a wordpress thing to limit it because if you use 100 that strange problem with extra dots appear …….. so 90 is the limitation
please feel free to change the number 15 in excerpt title to increase or decrease the title length
return currentText.substr(0, 15);
The final code used for the modifications are
// Excerpt length function custom_excerpt(){ ?> <script> jQuery(window).load(function(){ jQuery('.type-portfolio').each(function() { jQuery("div.entry-content").text(function(index, currentText) { return currentText.substr(0, 90); }); jQuery("div.entry-content").append("…"); }); }); </script> <?php } add_action('wp_footer', 'custom_excerpt'); // Excerpt title function custom_title(){ ?> <script> jQuery(window).load(function(){ jQuery('.type-portfolio').each(function() { jQuery("div.entry-title").text(function(index, currentText) { return currentText.substr(0, 10); }); jQuery("div.entry-title").append("…"); }); }); </script> <?php } add_action('wp_footer', 'custom_title');
Regards,
Vinay KashyapMarch 3, 2016 at 9:40 am #592509Hello Vinay
I’ve now changed the limit of the title from 10 to 50. Guess what? 3 of the portofolio items on that specific page has the title shorter then 50 chars, so all of these 3 portofolio items’ titles has the same issue with ……… at the end. This isn’t suitable, as you see and frankly, we don’t think it’s a limitation from WordPress.
Could we please get you to give it another shot?
All the best.
March 3, 2016 at 8:57 pm #592921Hey!
It’s a production site so i would prefer having FTP access and try the new code.
Please replace all the code both excerpt length and title with the below code
// Excerpt length function custom_excerpt(){ ?> <script> jQuery(window).load(function(){ jQuery('.type-portfolio').each(function() { jQuery(".entry-content").text(function(index, currentText) { return currentText.substr(0, 100); }); jQuery(".entry-title").text(function(index, currentText) { return currentText.substr(0, 50); }); }); jQuery(".type-portfolio").find(".entry-content").append("…"); jQuery(".type-portfolio").find(".entry-title").append("…"); }); </script> <?php } add_action('wp_footer', 'custom_excerpt');
If this don’t work correctly please setup FTP access for us.
Cheers!
Vinay KashyapMarch 3, 2016 at 9:07 pm #592926Hello Vinay
This works perfectly now! No more “………..” dots at the end if the text is shorter than the limit.
The only last problem that we have right now is that IF the text is shorter than the limit, then the “…” is ALWAYS added to the end, no matter what.As we posted in the very first post in this thread: “Basically if the text is 50 lettes and we need only 30, then the text is get cut after 30 letters and the “…” is added at the end.” – so the “…” should be added ONLY if the text is longer than the X amount of characters.
All the best.
March 4, 2016 at 8:30 am #593177Hey!
That’s great!
As I understand you require one script to work in both situation
Situation -1 : If the excerpt length is less than the available space you need the “…”
Situation -2 : If the excerpt length is more than the available space the “…” should be removedThis requires a complex algorithm and a lot of time to accomplish it you might have to hire a freelancer
We are more than happy to help you with any minor changes modifications you need. Please let us know if you need any other minor changes we are happy to help :)
Cheers!
Vinay KashyapMarch 4, 2016 at 8:55 am #593179Hello Vinay
Not really. Let me simplify it for you.
If the text is longer then the limit > cut it.
Otherwise > do nothing.That’s 1 situation, pretty simple, if you ask me.
All the best.
March 4, 2016 at 4:26 pm #593337Hi!
I’m not sure what you mean by cut the text? but as you might already know to reduce the excerpt length you just need to change the “XX” number in the below line of the final code provided.
return currentText.substr(0, XX);
Best regards,
Vinay KashyapMarch 4, 2016 at 6:41 pm #593445Hello Vinay
By cutting text I mean to reduce the text to the maximum amount of characters as it’s defined/limited in the function.
Let’s try again.
If the text is longer than the limit > reduce the text (to the max amount of characters defined by the function).
If the text is shorter than the limit > do nothing.Does it makes sense now?
All the best.
March 7, 2016 at 5:29 pm #594466Hello
We’ve got it covered.
// Excerpt length function custom_excerpt(){ ?> <script> jQuery(window).load(function(){ jQuery('.type-portfolio').each(function() { jQuery(".entry-content").text(function(index, currentText) { if (currentText.length > 100) { return currentText.substr(0, 100) + "…"; } }); jQuery(".entry-title").text(function(index, currentText) { if (currentText.length > 50) { return currentText.substr(0, 50) + "…"; } }); }); }); </script> <?php } add_action('wp_footer', 'custom_excerpt');
All the best.
March 7, 2016 at 6:44 pm #594532Hey!
Sorry for the delay we have been crazy busy off late.
Glad you got it sorted. jQuery is amazing isn’t it :)
Please feel free to get in touch with us if you have any questions.
Thank you for using Enfold :)
Regards,
Vinay Kashyap -
AuthorPosts
- You must be logged in to reply to this topic.