WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Place 'read more' link in PHP code. (6 posts)

  1. Junigo
    Member
    Posted 1 year ago #

    Hi Everyone,

    I am relatively new to PHP and need help with the following. On the category pages there are a few except on each page. There is the title (which can be clicked to the full article), followed by the text excerpt of 35 words but it just cuts there. I want to add a read more at the end so readers can click that to read more. Here is the code without the '...read more'.

    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php
    ob_start();
    the_content('Read the full post',true);
    $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
    ob_end_clean();
    ?>
    
    <?php
    $excerpt = $postOutput;
    $order   = array("<p>", "</p>");
    $replace = '';
    #$newstr = str_replace($order, $replace, $excerpt);
    #$newstr = strip_tags($newstr);
    $newstr = strip_tags($excerpt);
    echo '<p>'. string_limit_words($newstr,35) .'</p>'; 
    
    ?>

    Thanks in advance for your assistance.

    J.

  2. Marvel Labs
    Member
    Posted 1 year ago #

    Consider adding

    <?php the_excerpt(); ?><span class="read_more">">[ Read More → ]</span>

  3. Junigo
    Member
    Posted 1 year ago #

    Thanks Marvel Labs - I will try and let you know.

    J.

  4. Junigo
    Member
    Posted 1 year ago #

    This did not work. Any more suggestions?

    J.

  5. Junigo
    Member
    Posted 1 year ago #

    I got it solved. This is the code I added:

    <a href="<?php the_permalink(); ?>">...read more</a>

  6. AWN
    Member
    Posted 1 year ago #

    Hello dears.

    I am using a WordPress theme called "Pinboard" in my website however it has a permalink in each post footer section but I want to add a "Read more..." link as well.

    I tried adding above given code but it brings server error.

    I fount the following code in my functions.php

    if ( ! function_exists( 'pinboard_excerpt_length' ) ) :
    /**
     * Change the number of words shown in excerps
     *
     * @since Pinboard 1.0
     */
    function pinboard_excerpt_length( $length ) {
    	if( pinboard_is_teaser() ) {
    		if( has_post_format( 'aside' ) )
    			return 36;
    		else
    			return 22;
    	} else
    		return 40;
    }
    endif;
    
    add_filter( 'excerpt_length', 'pinboard_excerpt_length' );
    
    if ( ! function_exists( 'pinboard_excerpt_more' ) ) :
    /**
     * Changes the default excerpt trailing content
     *
     * Replaces the default [...] trailing text from excerpts
     * to a more pleasant ...
     *
     * @since Pinboard 1.0
     */
    function pinboard_excerpt_more($more) {
    	return ' …';
    }
    endif;
    
    add_filter( 'excerpt_more', 'pinboard_excerpt_more' );

    Please help me add a Read more link as well.

    Thanks in advance.

Topic Closed

This topic has been closed to new replies.

About this Topic