• Using WordPress 4.5.3 with Pique Child theme.
    my site is here : https://lesbeauxebooks.com/

    I’ve just added a panel to display the latest blog posts to my static home page, and i’m having a bit of trouble getting it set up the way i want.

    1. When i add a “more” link directly in the article, this is not taken into account when generating the excerpt, and only a very short snippet is displayed in the panel and in the posts page. I would like to have a slightly longer text and possibly a thumbnail-sized image.

    Since the “more” links in the articles were not working i tried making a manual excerpt using the dedicated box in the editor. This worked more or less but it does not seem to include a “more” link at all, unless i add the html code myself, and in that case it does not use the “more-link” style as it should even though i applied that class in my code.

    how can i get the manual break to be respected, and the “more” link to display in the proper style ?

    Currently I have 2 articles displayed. The latest one, “Remontons le temps”, has a personalised excerpt which i made in the “excerpt” box in the article editor ; the text is correct but styling is minimal and the more link is not correctly styled. The earlier one is an automatic excerpt, with a very short text, *but* the more link is automatically included, and properly styled both in the panel (styled text link with arrow) and in the posts page (button).

    2. Corollary question, I would like to modify the text of the “more” link used for blog posts. currently they look like this :

    <a class="more-link" href="url" rel="bookmark">Lire la suite de <span class="screen-reader-text">?&nbsp;title&nbsp;?</span></a>

    i would like to move the “de” into the screen-reader-text span before the title of the article, which makes more sense :

    <a class="more-link" href="url" rel="bookmark">Lire la suite <span class="screen-reader-text">de ?&nbsp;title&nbsp;?</span></a>

    which file is that code in ?

    Thanks in advance for any help. Pique is a great theme and very robust, but my sad lack of php skills are getting in my way.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there,

    Pique uses a function called the_excerpt() to automatically grab an excerpt from each of your recent posts for display on the front page. As you’ve discovered, this function grabs a set number of characters from each post and it’s not possible to override it using the more tag. (You can read a little more on this function here.)

    If it’s important for you to display more of your posts on the front page and to be able to use the more tag, you can replace the_excerpt() with another function, the_content(). (You can read a little more on this function here.)

    In order to make the above change to your theme’s PHP, you will first need to set up a child theme. Is this something you’ve already done? If not, the following guides provide good introductions to child themes, including steps to set one up:

    After you have completed that step, copy the parent’s components/content-excerpt.php file to your child theme’s directory and then open it in your favourite text/code editor.

    Locate the following code in that file:

    <div class="entry-content">
    	<?php the_excerpt(); ?>
    </div><!-- .entry-content -->

    Replace the_excerpt() with the_content(). Like so:

    <div class="entry-content">
    	<?php the_content(); ?>
    </div><!-- .entry-content -->

    After you have made the above steps, the posts on the front page of your site will be cut off at the point you enter the more tag.

    You can then customise the text that appears in the more tag’s link by manually adding the tag in your post’s editor:

    <!--more Keep on reading!-->

    The code surrounding the more tag changes a little with the above approach. If you’d still like to customise that after completing the above steps then let me know and I’ll be happy to help from there.

    Thread Starter zelda013

    (@zelda013)

    Hello Siobhan,
    thanks very much for your help.

    I’ve modified the components/content-excerpt.php file as you indicated (I am using a child theme already), and now the more link does work properly, however I’ve lost the original pique styles on that link which I would like to conserve (small caps + arrow text link on the home page and button style in the “see all posts” page).

    Can you tell me how to get that back ?

    I’d also like to modify the default more link as I mentioned above :

    currently they look like this :

    <a class="more-link" href="url" rel="bookmark">Lire la suite de <span class="screen-reader-text">?&nbsp;title&nbsp;?</span></a>

    i would like to move the “de” into the screen-reader-text span before the title of the article, which makes more sense :

    <a class="more-link" href="url" rel="bookmark">Lire la suite <span class="screen-reader-text">de ?&nbsp;title&nbsp;?</span></a>

    I’m just not sure where to find that code.

    Thanks again for your help.

    Thread Starter zelda013

    (@zelda013)

    Back again,
    actually i’ve just found this code in the inc/extras.php file which i think is the bit i want to modify :

    /*
     * Let's customize our excerpt a bit, so it looks better
     * First we decrease the default excerpt length, then
     * we give it a proper hellip for the more text.
     */
    function pique_custom_excerpt_length( $length ) {
    	return 27;
    }
    add_filter( 'excerpt_length', 'pique_custom_excerpt_length', 999 );
    
    function pique_custom_excerpt_more($more) {
    	$more_link = '<span class="read-more">';
    	$more_link .= '<a class="more-link" href="' . esc_url( get_the_permalink() ) . '" rel="bookmark">';
    	$more_link .= sprintf(
    		wp_kses( __( 'Read more %s', 'pique' ), array( 'span' => array( 'class' => array() ) ) ),
    		the_title( '<span class="screen-reader-text">"', '"</span>', false )
    	);
    	$more_link .= '</a></span>';
    	return '&hellip; ' . $more_link;
    }
    add_filter( 'excerpt_more', 'pique_custom_excerpt_more' );
    

    it mentions that the excerpt has been shortened, so i imagine i could modify the shortened length to make it a bit longer ? only i am not sure where to do that : i changed

    function pique_custom_excerpt_length( $length ) {
    	return 27;
    }

    to

    function pique_custom_excerpt_length( $length ) {
    	return 200;
    }

    just as a test (and put the components/content-excerpt.php back as it was originally), but that doesn’t seem to make a difference.

    i also modified this code :

    function pique_custom_excerpt_more($more) {
    	$more_link = '<span class="read-more">';
    	$more_link .= '<a class="more-link" href="' . esc_url( get_the_permalink() ) . '" rel="bookmark">';
    	$more_link .= sprintf(
    		wp_kses( __( 'Read more %s', 'pique' ), array( 'span' => array( 'class' => array() ) ) ),
    		the_title( '<span class="screen-reader-text">"', '"</span>', false )
    	);
    	$more_link .= '</a></span>';
    	return '&hellip; ' . $more_link;
    }

    to this :

    function pique_custom_excerpt_more($more) {
    	$more_link = '<span class="read-more">';
    	$more_link .= '<a class="more-link" href="' . esc_url( get_the_permalink() ) . '" rel="bookmark">';
    	$more_link .= sprintf(
    		wp_kses( __( 'Lire la suite %s', 'pique' ), array( 'span' => array( 'class' => array() ) ) ),
    		the_title( '<span class="screen-reader-text">"',de '"</span>', false )
    	);
    	$more_link .= '</a></span>';
    	return '&hellip; ' . $more_link;
    }

    but again, that didn’t change the text of the more link which is displayed…

    what am i doing wrong ?

    I’ve modified the components/content-excerpt.php file as you indicated (I am using a child theme already), and now the more link does work properly, however I’ve lost the original pique styles on that link which I would like to conserve (small caps + arrow text link on the home page and button style in the “see all posts” page).

    To replicate the styling, you can copy over the CSS that the theme applies to .pique-template-recent-posts .read-more a and apply it to .pique-template-recent-posts .more-link instead:

    .pique-template-recent-posts .more-link {
        display: inline;
        font-family: Karla, Arial, sans-serif;
        font-size: 12.8px;
        font-size: 0.8rem;
        font-weight: bold;
        letter-spacing: 1px;
        text-transform: uppercase;
        white-space: nowrap;
    }

    The above snippet would need to be added to your theme’s style.css file.

    The following would then add the arrow after the link:

    .pique-template-recent-posts .more-link:after {
        content: "?";
        display: inline-block;
        font-family: FontAwesome;
        font-size: 14px;
        font-style: normal;
        font-weight: normal;
        line-height: 1;
        text-decoration: none;
        -webkit-font-smoothing: antialiased;
        text-rendering: auto;
    }

    actually i’ve just found this code in the inc/extras.php file which i think is the bit i want to modify

    Modifying the theme’s existing functions is trickier and requires more knowledge of PHP than replacing the_excerpt() with the_content(). If you’d still like to go down that route then following guidance gives some good advice on overriding functions in a child theme:

    https://code.tutsplus.com/tutorials/a-guide-to-overriding-parent-theme-functions-in-your-child-theme–cms-22623

    Following the above guidance, this function could be added to your child theme’s functions.php file to override the parent’s pique_custom_excerpt_length() function:

    function pique_child_custom_excerpt_length( $length ) {
    	return 20;
    }
    add_filter( 'excerpt_length', 'pique_child_custom_excerpt_length', 9999 );

    Similarly, the following could be used to override the parent theme’s pique_custom_excerpt_more() function and add De prior to your post title:

    function pique_child_custom_excerpt_more($more) {
    	$more_link = '<span class="read-more">';
    	$more_link .= '<a class="more-link" href="' . esc_url( get_the_permalink() ) . '" rel="bookmark">';
    	$more_link .= sprintf(
    		wp_kses( __( 'Read more %s', 'pique' ), array( 'span' => array( 'class' => array() ) ) ),
    		the_title( '<span class="screen-reader-text">"De ', '"</span>', false )
    	);
    	$more_link .= '</a></span>';
    	return '&hellip; ' . $more_link;
    }
    add_filter( 'excerpt_more', 'pique_child_custom_excerpt_more', 15 );

    The above, however, would not give you the ability to customise excerpts on a post-by-post basis that replacing the_excerpt() with the_content() would.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to customise excerpts add "more" link to blog panel ?’ is closed to new replies.