Forums

[resolved] use an href within an if/else statement (3 posts)

  1. HorrorUK
    Member
    Posted 1 year ago #

    I'm trying to show a different image, with a link, depending on whether a user is logged in or not.

    What I'd like to do would be something like this:

    <?php
    if ( is_user_logged_in() ) {
        <A HREF="/"><IMG SRC="<?php bloginfo('template_directory'); ?>/images/createblog.jpg" border="0"></A>
    
    } else {
    <A HREF="/"><IMG SRC="<?php bloginfo('template_directory'); ?>/images/createblogloggedout.jpg" border="0"></A>
    
    };
    ?>

    However, as it doesn't allow commands within the statement, I can't figure out how to do it.

    How would I show an image within that structure?

    Thanks

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    you need to close the php tags before the html code and then open new php tags for more php code:
    principle:
    <?php PHP-CODE ?> HTML-CODE <?php PHP-CODE ?>
    even in an if statement.

    <?php
    if ( is_user_logged_in() ) { ?>
        <a href="/"><img src="<?php bloginfo('template_directory'); ?>/images/createblog.jpg" border="0"></a>
    
    <?php } else { ?>
    <a href="/"><img src="<?php bloginfo('template_directory'); ?>/images/createblogloggedout.jpg" border="0"></a>
    
    <?php };
    ?>
  3. HorrorUK
    Member
    Posted 1 year ago #

    Thanks, works perfectly now :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags