help: placing a link inside the php if else code

Discussion in 'HTML & Website Design' started by locals, Jul 2, 2013.

  1. #1
    What am I doing wrong?

    
    <?php
    if ( is_page('car-dealer-website')) {
       <a href=""> <img src="" border="0"> </a>
    } else {
        <img src="" border="0">
    }
    ?>
    
    Code (markup):
     
    locals, Jul 2, 2013 IP
  2. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #2
    if (is_page('car-dealer-website')) {
        echo "<a href=\"\"><img src=\"\" border=\"0\"></a>";
    } else {
        echo "<img src=\"\" border=\"0\">";
    }
    PHP:
     
    ActiveFrost, Jul 2, 2013 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    @activeFrost, GREAT example of why using double quotes with ECHO is ***tarded.

    Also, in "modern" HTML there is no such thing as a BORDER attribute; unless you're crapping out HTML 3.2 and slapping 4 tranny or 5 lip-service on it, staying in 'transition' from 1997 to 1998 coding practices, you have NO business using BORDER, and there's another attribute called 'ALT' that is NOT OPTIONAL.

    If you were doing more than just outputting markup, I'd keep the if statement...

    <?php
    
    if ( is_page('car-dealer-website')) {
    	echo '<a href=""><img src="" alt=""></a>';
    } else {
    	echo '<img src="" alt="">';
    }
    
    ?>
    Code (markup):
    But if it was going to just be 'this has anchors, this doesn't" I'd use a inline eval instead... storing is_page's result in a var since that would likely be faster than calling the function twice.

    <?php
    
    echo (
    	($isPage = is_page('car-dealer-website')) ? '<a href="">' : ''
    ),'<img src="" alt="" />',(
    	$isPage ? '</a>' : ''
    );
    
    ?>
    Code (markup):
     
    deathshadow, Jul 2, 2013 IP
  4. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #4
    Isn't everything you do not like ***tarded? There is NOTHING WRONG with using double quotes!
     
    ActiveFrost, Jul 2, 2013 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    Apart from them being slower (more so at the bytecode compile stage than exec) due to having to look for more things, the wasted time and effort of having to escape every time you want a double quote in the output (something that in HTML is REALLY common) -- I just don't get the infatuation (and resulting ugly code) with them certain PHP developers seem to have.
     
    deathshadow, Jul 2, 2013 IP
  6. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #6
    Deathshadow has a bad communication skills, but I do agree with him on this one.
     
    HuggyStudios, Jul 2, 2013 IP