WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] If and Else (8 posts)

  1. Sparky
    Member
    Posted 8 years ago #

    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.... :P

    <?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"...

  2. geoffe
    Member
    Posted 8 years ago #

    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.

  3. Sparky
    Member
    Posted 8 years ago #

    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?

  4. Amelie
    Member
    Posted 8 years ago #

    I have replied to your topic about this at CodeGrrl. :)

  5. geoffe
    Member
    Posted 8 years ago #

    You want to use Conditional Tags, in particular these.

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

  6. Sparky
    Member
    Posted 8 years ago #

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

  7. geoffe
    Member
    Posted 8 years ago #

    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.

  8. Sparky
    Member
    Posted 8 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic