The excerpt of the service section cuts the sentences before the end of the line

edited June 2014 in HealthCentre
Hi!

I have a site in different languages, and the problem is that the excerpt of the service section is based on a specific number of characters (i.e. 245). I tried to make the excerpts to fit in all the languages by varying from 245 until 300, but it didn't work. What works in one language, doesn't work in another. 

Also, look what happens in the second service of the German version when I try to set it in the same line as the others...

I attach some snapshots to clarify what I mean.

Is there any posibility of fixing this issue, for example, by automatically adding "..." at the end of the last word?

Many thanks in advance.

Regards,

Yunny
español.PNG
1206 x 535 - 40K
english.PNG
1195 x 529 - 35K
french.PNG
1191 x 522 - 34K
german.PNG
1195 x 528 - 37K

Comments

  • Hi 
     To fix your issues you have to changes into  the code of excerpt.php file 
     that is available at function/Excerpt Folder. 

    Find these lines of code at the top of the file

    function get_home_service_excerpt(){
    global $post;
    $excerpt = get_the_content();
    $excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
    $excerpt = strip_shortcodes($excerpt);
    $original_len = strlen($excerpt);
    $excerpt = substr($excerpt, 0, 245);
    $len=strlen($excerpt);  
    if($original_len>245)
      $excerpt = $excerpt;
    return $excerpt;
    }
    And replace  with this   code 

    function excerpt($limit) {
         $excerpt = explode(' ', get_the_excerpt(), $limit);
         if (count($excerpt)>=$limit) {
         array_pop($excerpt);
         $excerpt = implode(" ",$excerpt).'...';
         } else {
             $excerpt = implode(" ",$excerpt);
            }
         $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
          return $excerpt;
        } 

    And you also have to some changes in index-service.php file 
    find the line of code   echo get_home_service_excerpt(); and replace with this 
    echo excerpt(35);

    Thanks 
    akhilesh
  • Hi

    Did That work 

    Thanks

    Priyanshu
  • Hi, Priyanshu!

    It didn't work... :( When I replaced echo get_home_service_excerpt(); by echo excerpt(35); the site was all broken (I mean, the service section didn't appear, the fonts were different, the css was not working...)
  • Hello 

    You also have to Replace the code in the excerpt.php file ,

    As we discussed above 

    Thanks

    Akhilesh
  • edited July 2014
    Yes, of course, I did it first. But it doesn't work... I did the changes in the child theme. May it be that the reason why it doesn't work?
  • Hello 

    Sorry for your Inconvenience .

    Pls give your admin detail, on this email address.



    Thanks 


    akhlesh
  • edited July 2014
    Hello yukhays

    I locally check this code and as well as server  , The code  is working as you want .

    ( You can see on my testing server follow LINK on this I set  excerpt  word limit 35 .You can Increase or Decrease )

    So finally i want to suggest you ,Remove all the plugins and then make changes into the file as i suggested in above discussion  .

    Then tell me the issue gets resolved or not 
     
    Thanks 

    Akhilesh

Sign In or Register to comment.