Support » Plugin: Nooz » Two excerpts fields

  • Resolved jerepowers

    (@jerepowers)


    SUGGESTION ONLY

    How much trouble would it be to add a second excerpt box? I have a news page – the list of news releases – showing headlines with excerpts. The client wants to put news on the home page, but wants a shorter excerpt to show there.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor farinspace

    (@farinspace)

    1) One quick way to do this is to trim the excerpt specifically on the home page, something like this in your functions.php file:

    add_filter( 'nooz_post_data', function( $post_data ) {
        if ( is_front_page() ) $post_data['excerpt'] = wp_trim_words( $post_data['excerpt'], 10, '...' );
        return $post_data;
    } );
    

    2) However if you want specifically different excerpts for home vs everywhere else you can enable ‘custom-fields’ for press releases/coverage and create a custom field. In the example below you could add a new custom field named my_alt_excerpt which is only used on the front-page. Something like this in your functions.php file:

    add_filter( 'nooz/post-types/nooz_release/options', 'my_enable_custom_fields' );
    add_filter( 'nooz/post-types/nooz_coverage/options', 'my_enable_custom_fields' );
    function my_enable_custom_fields( $options ) {
        $options['supports'][] = 'custom-fields';
        return $options;
    }
    
    add_filter( 'nooz_post_data', function( $post_data ) {
        if ( ! is_front_page() ) return $post_data;
        global $post;
        $alt_excerpt = get_post_meta( $post->ID, 'my_alt_excerpt', TRUE );
        $post_data['excerpt'] = $alt_excerpt ?: wp_trim_words( $post_data['excerpt'], 10, '...' );
        return $post_data;
    } );
    
    Plugin Contributor farinspace

    (@farinspace)

    My recommendation would be option #1, this is because only one excerpt needs to be created and maintained.

    Option #2, allows for custom secondary excerpts but will also fallback to the default excerpt if a secondary excerpt is not present.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Two excerpts fields’ is closed to new replies.