WordPress.org

Forums

Twenty Fourteen
[resolved] 'read more' link not displayed after excerpt (8 posts)

  1. Morand13
    Member
    Posted 1 year ago #

    Hi,
    I am new to this and don't like changing much code. I have a child theme up and running as I had to change the content to a summary on page. I did that by doing the following and it worked:
    <?php if ( is_search() ) : ?>
    to
    <?php if ( is_search() || is_home() ) : ?>

    NOW, I want to have a link at the end of summary that has 'read more'

    Can anyone help me do this?
    Thanks in advance!

  2. bravokeyl
    Member
    Posted 1 year ago #

    Add the following to the functions.php of child theme

    function child_excerpt_more( $more ) {
    	return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read More</a>';
    }
    add_filter( 'excerpt_more', 'child_excerpt_more' );

    More details check here

  3. Morand13
    Member
    Posted 1 year ago #

    Brilliant, worked perfectly! Thanks.

  4. betholsoncreative
    Member
    Posted 1 year ago #

    Thanks! This worked great for me as well!

  5. Joseph
    Member
    Posted 1 year ago #

    Hi @bravokeyl

    To show only excerpt, I replace the_content with the_excerpt in my child theme content.php file.

    But it doesn't show "Read more" when I try to apply your code in my child theme functions.php file. Any thought of it?

    Regards,
    Joseph

  6. bravokeyl
    Member
    Posted 1 year ago #

    can you give me the site url...

  7. bravokeyl
    Member
    Posted 1 year ago #

    Also it is good to open a new post..rather than posting here.

  8. Tche111
    Member
    Posted 1 year ago #

    Hello Bravokeyl,
    I don't why these posted solutions rarely work for me. :( I added your code to functions.php in my childtheme... but the excerpts keep on showing [...] without a link (and without any error message...)
    Here is my functions.php:

    <?php
    if ( function_exists('register_sidebar') ) {
     register_sidebar( array(
      'name' => __( 'First Footer Widget Area', 'twentyfourteen' ),
      'id' => 'sidebar-4',
      'description' => __( 'First footer widget area', 'twentyfourteen' ),
      'before_widget' => '<div class="textwidget">',
      'after_widget' => '</div>',
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
     ) );
     // Area 6, located in the footer. Empty by default.
     register_sidebar( array(
      'name' => __( 'Second Footer Widget Area', 'twentyfourteen' ),
      'id' => 'sidebar-5',
      'description' => __( 'Second footer widget area', 'twentyfourteen' ),
      'before_widget' => '<div class="textwidget">',
      'after_widget' => '</div>',
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
     ) );
     // Area 7, located in the footer. Empty by default.
     register_sidebar( array(
      'name' => __( 'Third Footer Widget Area', 'twentyfourteen' ),
      'id' => 'sidebar-6',
      'description' => __( 'The third footer widget area',  'twentyfourteen' ),
      'before_widget' => '<div class="textwidget">',
      'after_widget' => '</div>',
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
     ) );
     // Area 8, located in the footer. Empty by default.
     register_sidebar( array(
      'name' => __( 'Fourth Footer Widget Area', 'twentyfourteen' ),
      'id' => 'sidebar-7',
      'description' => __( 'The fourth footer widget area', 'twentyfourteen' ),
      'before_widget' => '<div class="textwidget">',
      'after_widget' => '</div>',
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
     ) );
    }
    /** Génèse des ancres
    */
    function replace_ca($matches){
      return '<h'.$matches[1].$matches[2].' id="'.sanitize_title($matches[3]).'">'.$matches[3].'</h'.$matches[4].'>';
    }
    //Ajout d'un filtre sur le contenu
    add_filter('the_content', 'add_anchor_to_title', 12);
    function add_anchor_to_title($content){
      if(is_singular('post')){ // s'il s'agit d'un article
        global $post;
        $pattern = "/<h([2-4])(.*?)>(.*?)<\/h([2-4])>/i";
    
        $content = preg_replace_callback($pattern, 'replace_ca', $content);
        return $content;
      }else{
        return $content;
      }
    }
    /** Function automenu( $echo = false )
    */
    function automenu(){
      global $post;
      $obj = '<nav class="sommaire-article"><ul>';
      $original_content = $post->post_content;
    
    //on récupère les titres
     $patt = "/<h([2-4])(.*?)>(.*?)<\/h([2-4])>/i";
      preg_match_all($patt, $original_content, $results);
    
    //on génère les liens
      foreach ($results[3] as $k=> $r) {
        $obj .= '<li><a href="#'.sanitize_title($r).'" class="title_lvl'.$results[1][$k].'">'.$niveau.$r.'</a></li>';
      }
    
      $obj .= '</nav>';
      if ( $echo )
        echo $obj;
      else
        return $obj;
    }
    // shortcode
    add_shortcode('sommaire','automenu');
    //template
    automenu( true );
    
    /** Function liens sur lire plus
    function child_excerpt_more( $more ) {
    	return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read more</a>';
    }
    add_filter( 'excerpt_more', 'child_excerpt_more' );

    Do you have any idea?
    Hopefully,
    Tche'ers

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic