Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1373805

    Hi I have this for portfolio grid –

    add_filter('avf_portfolio_grid_excerpt', function($excerpt, $entry) {
       $excerpt = get_field( 'the_project', $entry->ID );
       return $excerpt; 
    }, 10, 2);

    How do I do the same for blog posts? I tried:

    add_filter('avf_blog_posts_excerpt', function($excerpt, $entry) {
       $excerpt = get_field( 'the_project', $entry->ID );
       return $excerpt; 
    }, 10, 2);

    But it didn’t work – anyone know the correct filter?

    Thanks in advance.

    #1373831

    Hey domchocolate,

    Thank you for the inquiry.

    You can use the get_the_excerpt filter to adjust the excerpt of the default posts.

    // https://developer.wordpress.org/reference/hooks/get_the_excerpt

    Make sure to check for the post type.

    Best regards,
    Ismael

    #1373837

    Sorry – I’m no expert. Can you elaborate? How do I add that to my code above? The excerpt needs to be replaced by a custom field.

    Thanks in advance

    Dominic

    #1373844

    Hi Dominic,

    Please try to use this filter:

    // Use custom excerpt for Blogposts for grid layout
    add_filter("avf_post_slider_entry_excerpt", function($excerpt, $prepare_excerpt, $permalink, $entry, $class) {
    	$excerpt = get_field( 'the_project', $entry->ID );
       	return $excerpt; 
    }, 10, 5);
    
    // Use custom excerpt for Blogposts in all layout except grid
    add_filter('get_the_excerpt', function($excerpt, $entry) {
       $excerpt = get_field( 'the_project', $entry->ID );
       return $excerpt; 
    }, 10, 2);

    Hope this helps.

    Best regards,
    Nikko

    #1373864

    Thanks Nikko – that’s great. And works a treat. Is there a way to put a word count – say the first 50 words and then add a “…” at the end or a [READ MORE]??

    #1374220

    Hi domchocolate,

    Please try to replace the last code I gave with this one:

    function modify_excerpt($excerpt) {
       $label = "Read More";
       $limit = 50;
       $excerpt = string_limit_words( $excerpt, $limit) . '…';
       $excerpt .= '<a href="" class="avia-button av-readmore avia-icon_select-no avia-size-small avia-position-center avia-color-theme-color"><span class="avia_iconbox_title">' . $label . '</span></a>';
       return $excerpt;
    }
    
    function string_limit_words($string, $word_limit) {
       $words = explode(' ', $string, ($word_limit + 1));
    	
       if(count($words) > $word_limit) {
          array_pop($words);
       }
    	
       return implode(' ', $words);
    }
    
    // Use custom excerpt for Blogposts for grid layout
    add_filter("avf_post_slider_entry_excerpt", function($excerpt, $prepare_excerpt, $permalink, $entry, $class) {
       $custom_excerpt = get_field( 'the_project', $entry->ID );
    	
       if ( $custom_excerpt ) {
          $excerpt = modify_excerpt($custom_excerpt);
       }
    	
       return $excerpt; 
    }, 10, 5);
    
    // Use custom excerpt for Blogposts in all layout except grid
    add_filter('get_the_excerpt', function($excerpt, $entry) {
       $custom_excerpt = get_field( 'the_project', $entry->ID );
    	
       if ( $custom_excerpt ) {
          $excerpt = modify_excerpt($custom_excerpt);
       }
    	
       return $excerpt; 
    }, 10, 2);

    Just change the label and limit as you see fit.
    Hope this helps.

    Best regards,
    Nikko

    #1374259

    Hi Nikko – thanks for this but no cigar I’m afraid. It’s pulling the excerpt from the_project through but not cutting it to 50 words.

    See links below and PW in private content.

    Masonry portfolio element:
    https://owe.brother.design/project-item/oxford-station-western-side/

    Blog post element:
    https://owe.brother.design/sites/oxpens-phase-1/

    Thanks in advance
    Dominic

    #1374300

    Also is it possible to use the excerpt from an excerpt field when the_project either hasn’t been utilised or isn’t on another post type?
    In other words:
    Post types I have =
    Portfolio items – use the_project custom field as excerpt
    Sites – use the_project custom field as excerpt
    Posts – doesn’t have the the_project custom field so use excerpt field for the excerpt.

    Thanks in advance.

    #1374852

    Hi domchocolate,

    I apologize for the delayed response.
    I have tested the code and it works, can you create a staging site? where we can try to check why it’s not working on your end.
    Also, please give us temporary admin access on it.

    Also is it possible to use the excerpt from an excerpt field when the_project either hasn’t been utilised or isn’t on another post type?
    Yes, it’s possible that why there’s a code to check it:

    if ( $custom_excerpt ) {
       $excerpt = modify_excerpt($custom_excerpt);
    }

    Best regards,
    Nikko

    #1375099

    Hi Nikko

    Basically, it works for the posts element, see – https://owe.brother.design/sites/oxpens-phase-1/ under heading Other development opportunities when the post element is calling a custom post and using the_project as an excerpt. But for some reason not in the second post element on the same page under the heading Related news and updates – this one uses a post element calling standard posts from the blog and using a standard excerpt field (doesn’t shorten the excerpt to 50 words or add [more info].

    Also, it doesn’t work at all for portfolio grids, see – https://owe.brother.design/project-item/oxford-station-western-side/ under heading Other projects.

    Code added as Code snippet

    Any thoughts?

    #1375101

    BTW I sorted the portfolio grid by using the post element to call portfolio items instead.

    #1375106

    One other thing – I created this test page. This uses blog posts element throughout (no portfolio grids). https://owe.brother.design/excerpt-test/

    Blog post element 1 – calls standard posts and uses the standard excerpt field. This element is not working as I’d like because it does not shorten the excerpt or add ‘… Read more >’.
    Blog post element 2 – calls portfolio posts and uses the_project custom field as excerpt.

    You’ll also notice that when the excerpt is longer than 50 words and the excerpt is edited then the ‘… Read more’ works correctly by being inserted after the 50th word.

    If excerpt is shorter than 50 words then the ‘… Read more’ is after a line break which is inconsistent and not as desired. Also when the excerpt is shorter than 50 words it’s displaying the full excerpt and therefore the ‘…’ is not actually necessary or grammatically accurate. Can we remove the ‘…’ under those parameters and display the ‘Read more’ directly after the last word of the excerpt?

    Does that makes sense? And thanks in advance.

    Dominic

    • This reply was modified 4 days, 7 hours ago by  domchocolate.
Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.