[resolved] If and Else (8 posts)

  1. Sparky
    Posted 10 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()) {
    echo '<a href="<?php the_permalink() ?>" rel="bookmark">Continue Reading</a> | '
    } else {
    } ?>

    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
    Posted 10 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.

    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
    Posted 10 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
    Posted 10 years ago #

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

  5. geoffe
    Posted 10 years ago #

    You want to use Conditional Tags, in particular these.

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

  6. Sparky
    Posted 10 years ago #

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

  7. geoffe
    Posted 10 years ago #

    did you read the documentation at this page:

    Perhaps you could describe what effect you are after.

  8. Sparky
    Posted 10 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