Forums

[resolved] Conditional Tags: Did I code this correctly? Content not showing up (4 posts)

  1. databell96
    Member
    Posted 6 months ago #

    I'm still a bit new to Conditional Tags and the deal is depending on the page you are on, you get either one set of Social Media links or another for all other pages. Simple if:else or so I thought. When I tried the following code, nothing appeared in my div. Just blank.

    <ul id="social">
            <?php if ( is_page( array( 1476, 1482, 1484, 1487, 1489 ) ) ) { ?>
            <li id="facebook"><a href="https://www.facebook.com/XXXX" title="Facebook" target="_blank">Facebook</a></li>
            <li id="twitter"><a href="http://twitter.com/XXXX" title="Twitter" target="_blank">Twitter</a></li>
            } else {
            <li id="facebook"><a href="https://www.facebook.com/YYYY" title="Facebook" target="_blank">Facebook</a></li>
            <li id="twitter"><a href="http://twitter.com/YYYY" title="Twitter" target="_blank">Twitter</a></li>
            <?php } ?>
          </ul>

    Seems OK but it's not. Any idea what I'm supposed to do to make this code appear properly?

  2. mrwweb
    Member
    Posted 6 months ago #

    Databell,
    You never reopen your php code for the else statement.

    Try this:

    <ul id="social">
            <?php if ( is_page( array( 1476, 1482, 1484, 1487, 1489 ) ) ) { ?>
            <li id="facebook"><a href="https://www.facebook.com/XXXX" title="Facebook" target="_blank">Facebook</a></li>
            <li id="twitter"><a href="http://twitter.com/XXXX" title="Twitter" target="_blank">Twitter</a></li>
            <?php } else { ?>
            <li id="facebook"><a href="https://www.facebook.com/YYYY" title="Facebook" target="_blank">Facebook</a></li>
            <li id="twitter"><a href="http://twitter.com/YYYY" title="Twitter" target="_blank">Twitter</a></li>
            <?php } ?>
          </ul>

    The above should work, but I personally prefer the extended if/else syntax.

    <ul id="social">
            <?php if ( is_page( array( 1476, 1482, 1484, 1487, 1489 ) ) ) : ?>
            <li id="facebook"><a href="https://www.facebook.com/XXXX" title="Facebook" target="_blank">Facebook</a></li>
            <li id="twitter"><a href="http://twitter.com/XXXX" title="Twitter" target="_blank">Twitter</a></li>
            <?php else : ?>
            <li id="facebook"><a href="https://www.facebook.com/YYYY" title="Facebook" target="_blank">Facebook</a></li>
            <li id="twitter"><a href="http://twitter.com/YYYY" title="Twitter" target="_blank">Twitter</a></li>
            <?php endif; ?>
          </ul>

    Let me know if this doesn't work.

  3. databell96
    Member
    Posted 6 months ago #

    Yes, that was the trick. I just tested it and the social media links do show up and they are the proper links for the proper pages. Thank you.

  4. mrwweb
    Member
    Posted 6 months ago #

    Glad I could help!

Reply

You must log in to post.

About this Topic