• The following code works in my index.php page:


    <?php if(is_category() || is_archive()) {
    the_excerpt();
    } else {
    the_content('Read the rest of this entry &raquo;');
    } ?>

    But, when I add the line to “Read More…” to the excerpt display, I get a parse error.


    <?php if(is_category() || is_archive()) {
    the_excerpt();
    <a href="<?php the_permalink() ?>" title="full post">Read more...</a>
    ;
    } else {
    the_content('Read the rest of this entry &raquo;');
    } ?>

    I’ve tried all sorts of ways to do this and I can’t get it to work. Any ideas? (I’m not obviously good at this.)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The “Read more” link in your excerpt portion is not part of the PHP. This should work:

    <?php if(is_category() || is_archive()) {
    the_excerpt(); ?>
    <p><a href="<?php the_permalink() ?>" title="full post">Read more...</a></p>
    <?php } else {
    the_content('Read the rest of this entry &raquo;');
    } ?>

    Thread Starter slobizman

    (@slobizman)

    Thank you very much! It works great.

    Now I’m trying to move the “Read more…” up to the same line as where the the excerpt ends, instead of a paragraph break down below it. I took out the paragraph tags and it still didn’t do it. The excerpt tag itself must add the line spacing.

    Please let me know if there is a way to do this–to be specific, I’d like the “read more…” to follow the last character of the excerpt.

    That’s a trickier issue of sorts in WP because of the paragraph tags added to the excerpt’s content. A way around it might be to use the_excerpt_rss(), or perhaps even the_content_rss(), like so:

    <?php if(is_category() || is_archive()) { ?>
    <p><?php the_content_rss('', 1, '', 50); ?>
    <a href="<?php the_permalink() ?>" title="full post">Read more...</a></p>
    <?php } else {
    the_content('Read the rest of this entry &raquo;');
    } ?>

    (Note slight change in php tagging; the last parameter value in the_content_rss() (50) defines the amount of words to display before cutting the text.)

    The limitation to this is that either of the _rss tags removes all html formatting for your “excerpt”, placing everything on one line.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How to change “Read More” PHP code’ is closed to new replies.