• Resolved Sparky

    (@sparky)


    I tried modifying a code so that on the home page and all archives types of pages (category, date) it would have only the excerpt and then a “continue reading” link (without using the ‘more’ thing in the user panel), but if it’s the single page then it would have the whole story without that link. I modified another code but it doesn’t work…. 😛

    <?php if(is_home() || is_archive()) {
    the_excerpt();
    echo '<a href="<?php the_permalink() ?>" rel="bookmark">Continue Reading</a> | '
    } else {
    the_content();
    } ?>

    It works fine when I take out the echo line. What I want it to do is have the excerpt (the_excerpt();) and then the link to “continue reading”…

Viewing 7 replies - 1 through 7 (of 7 total)
  • geoffe

    (@geoffe)

    There is an important difference between using single and double quotes in PHP’s interpretation.

    Code between double quotes will be parsed, but code between single quotes will not.

    But the reason nothing was printed was because you are missing a semi-colon — ; — at the end of the echo line, after the single quote.

    Try:
    echo "<a href='<?php the_permalink() ?>' rel='bookmark'>Continue Reading</a> | ";

    And have you tried using the_content(‘Continue Reading’);

    EDIT: the suggested code was modified because escaping quotes with \ does not work here.

    Sparky

    (@sparky)

    Thanks. 🙂

    Also, how can you do the if/else if the if is a certain url? Like if it’s http://thissite.com/page.php then you echo this, else you echo that?

    Amelie

    (@amelie)

    I have replied to your topic about this at CodeGrrl. 🙂

    geoffe

    (@geoffe)

    You want to use Conditional Tags, in particular these.

    e.g.
    if( is_page() ) : ?> This is what will show. <?php endif; ?>

    Sparky

    (@sparky)

    Can it be if(is_URLofApage()): ?> ?? Would that work?

    geoffe

    (@geoffe)

    did you read the documentation at this page:
    http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

    Perhaps you could describe what effect you are after.

    Sparky

    (@sparky)

    Never mind. Someone helped me figure it out. (I was trying to say if its a page outside WP.) Thanks a lot, though!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘If and Else’ is closed to new replies.