Forums

[resolved] How to display the_content ONLY if read more else the_excerpt? (5 posts)

  1. jannhowell
    Member
    Posted 1 year ago #

    Hello,

    I am trying to display automatic post excerpts on the main index with a link leading to the entire post. When I use <?php the_excerpt(); ?> <span class="custom_read_more"><a href="<?php the_permalink(); ?>">Read Entry → </a></span> it displays two "read more" links on posts that have <!--more--> in the content area.

    What I'm looking for is something like:

    if: <?php the_content('Read More'); ?>
    then: <?php the_content(); ?>
    else: <?php the_excerpt(); ?> <span class="custom_read_more"><a href="<?php the_permalink(); ?>">Read Entry → </a></span>

    I know that's not actual code, just needed to illustrate what I'm looking for.

    If this is possible, please help. Thanks in advance!

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    the first line checks for the code of a more link in the content, and then acts accordingly:

    <?php if(strpos(get_the_content(),'#more-')) {
    the_content('Read More');
    } else {
    the_excerpt(); ?> <span class="custom_read_more"><a href="<?php the_permalink(); ?>">Read Entry → </a></span>
    <?php }; ?>
  3. jannhowell
    Member
    Posted 1 year ago #

    tried the code above, but still duplicates the "read more" link on posts with <!-- more -->

    :(

  4. alchymyth
    The Sweeper
    Posted 1 year ago #

    a link to your site mioght help to illustrate your problem.

    and or the name of your theme.

    there might be some code in functions.php that appends the 'read-more' to excerpts.

    check the docu:
    http://codex.wordpress.org/Template_Tags/the_excerpt
    http://codex.wordpress.org/Template_Tags/the_excerpt#Make_the_.22read_more.22_link_to_the_post

    http://codex.wordpress.org/Customizing_the_Read_More

    also, it might help if you could paste the full code of your template into a http://wordpress.pastebin.com/ and post the link to it here.

  5. jannhowell
    Member
    Posted 1 year ago #

    you were right about the functions.php, it works fine now.

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic