This topic has 4 replies, 2 voices, and was last updated 9 years by 5high-photohub.

  • Author
  • #52360
     5high-photohub
    Participant

    Hi,

    I’m using the post excerpts displaying in thumbnails (left small thumb) but the excerpts are really short and look way too small compared to the depth of the thumbnails (see attched).

    How can I increase the amount of text shown here?

    Many thanks.

    Attachments:
    You must be logged in to view attached files.
    #52391
     sharmstr
    Moderator

    Kleo has its own function for excerpts. Copy the function into your child theme functions.php file and edit as necessary.

    COPY CODE
    \[[^\]]*\]

    By default, Kleo will limit the characters to 50 or the words to 20. I’ve changed the characters to 100 above. If you want to increase that, change the ‘100’ in two places to whatever you want. If you want to change it to words, set $chars = false and change $limit = *how many words you want*

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #52528
     5high-photohub
    Participant

    Thanks Sharmstr,

    I’ve tried it both ways and neither work – in fact they both make the excerpt shorter!? The code I used was this for increasing characters to 100 (as yours above) which produced NO excerpt at all:

    COPY CODE
    function kleo_excerpt( $limit = 20, $chars = true ) {
     
            $except_initial = strip_tags( get_the_excerpt() );
     
            if ( $chars ) {
                $excerpt = explode( ' ', $except_initial, '100' );
                if ( count( $excerpt ) >= '100' ) {
                    array_pop( $excerpt );
                    $excerpt = implode( " ", $excerpt ) . '...';
                } else {
                    $excerpt = implode( " ", $excerpt ) . '';
                }
                /** TODO */
                $excerpt = preg_replace( '<code>\[[^\]]*\]</code>', '', $excerpt );
                return '<p>' . $excerpt . '</p>';
            } else {
                $excerpt = $except_initial;
                return '<p>'. substr( $excerpt, 0, $limit ) . ( strlen( $excerpt ) > $limit ? '...' : '' ) . '</p>';
            }
    }

    and this for limiting by words to 50 which made the excerpt even shorter:

    COPY CODE
    function kleo_excerpt( $limit = 50, $chars = false ) {
     
            $except_initial = strip_tags( get_the_excerpt() );
     
            if ( $chars ) {
                $excerpt = explode( ' ', $except_initial, '100' );
                if ( count( $excerpt ) >= '100' ) {
                    array_pop( $excerpt );
                    $excerpt = implode( " ", $excerpt ) . '...';
                } else {
                    $excerpt = implode( " ", $excerpt ) . '';
                }
                /** TODO */
                $excerpt = preg_replace( '<code>\[[^\]]*\]</code>', '', $excerpt );
                return '<p>' . $excerpt . '</p>';
            } else {
                $excerpt = $except_initial;
                return '<p>'. substr( $excerpt, 0, $limit ) . ( strlen( $excerpt ) > $limit ? '...' : '' ) . '</p>';
            }
    }

    I’ve obviously copied it incorrectly somehow. Can you check it for me?

    (I’ve attached screen shots of both FYI.)

    Many thanks,
    J

    Attachments:
    You must be logged in to view attached files.
    #52548
     sharmstr
    Moderator

    I think I was smoking something earlier. I just tested this and this seems to be whats works

    COPY CODE
    \[[^\]]*\]
    COPY CODE
    \[[^\]]*\]

    Just change the limit.

    But keep in mind that it initially gets the standard WP excerpt which is limited to 50 words by default.

    If it were me, I’d just do this

    COPY CODE
    
    function kleo_excerpt( $limit = 10, $chars = true ) {
            return strip_tags( get_the_excerpt() );
    }
    
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #52593
     5high-photohub
    Participant

    Thanks for that. I did try your last recommendation with an increase to the default of 50 wors, so like this:

    COPY CODE
    function kleo_excerpt( $limit = 50, $chars = false ) {
            return strip_tags( get_the_excerpt() );
    }

    and it works great!

    Thanks again.

Viewing 5 posts - 1 through 5 (of 5 total)

The forum ‘KLEO’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?