WordPress.org

Forums

Simple 'read more' problem, probably a quick answer?! (4 posts)

  1. roxette cassette
    Member
    Posted 3 years ago #

    Hi,

    I have an non wordpress website, and use wordpress for the latest news section only. This works great on the latest news page, but I want to pull in the most recent 2 excerpts onto the homepage also. All my wordpress files are located on the server under a directory named 'news'.

    I can pull the 2 excerpts into the home page using this code

    <?php query_posts('showposts=2'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <em><?php the_date(); ?></em><br/>
    <?php the_excerpt (); ?>
    <?php endwhile;?>

    However, I need to either change the 'read more' link to the direct URL of my latest news page, or remove it altogether and add my own link...

    I gather I may need to amend the code in the post_template.php file however after multiple experiments I just can't get it to work. Im sure its quite straightforward but its becoming very frustrating now.

    All help greatly appreciated,

    thankyou!

  2. wptorgue
    Member
    Posted 3 years ago #

    You can filter the excerpt links, like so;

    function new_excerpt_more($more) {
           global $post;
    	return '<a href="'. get_permalink($post->ID) . '">Read the Rest...</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    Source: http://codex.wordpress.org/Function_Reference/the_excerpt

  3. roxette cassette
    Member
    Posted 3 years ago #

    Thanks, I have read the source but still a bit confused, but how do i amend this relevant to my situation?

    I added this to function.php as stated in the source

    function new_excerpt_more($more) {
           global $post;
    	return '<a href="http://MYURLHERE.com">Read more...</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    However I get this error,

    Fatal error: Call to undefined function add_filter()

    ?

  4. roxette cassette
    Member
    Posted 3 years ago #

    Does anyone have any advice for me on this? Still trying to work it out :(

    Thankyou!

Topic Closed

This topic has been closed to new replies.

About this Topic