• Resolved Junigo

    (@junigo)


    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Consider adding

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

    Thread Starter Junigo

    (@junigo)

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

    J.

    Thread Starter Junigo

    (@junigo)

    This did not work. Any more suggestions?

    J.

    Thread Starter Junigo

    (@junigo)

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

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

    AWN

    (@wakilnikzad)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Place 'read more' link in PHP code.’ is closed to new replies.