• Resolved dprogramb

    (@dprogramb)


    I have the following line of code in a page template and I want to make it conditional on the post category. The problem I’m facing is nested PHP.

    <p><?php the_time(__("F j, Y", 'organicthemes')); ?> &middot; <a href="<?php the_permalink(); ?>#respond"><?php comments_number(__("Leave a Comment", 'organicthemes'), __("1 Comment", 'organicthemes'), __("% Comments", 'organicthemes')); ?></a>?<?php edit_post_link(__("(Edit)", 'organicthemes'), '', ''); ?></p>

    I do something like this, and it doesn’t work…for obvious reasons.

    <?php if (!in_category(array('bishop-column','bishops-blog')))
    				<p><?php the_time(__("F j, Y", 'organicthemes')); ?> &middot; <a href="the_permalink(); #respond> comments_number(__("Leave a Comment", 'organicthemes'), __("1 Comment", 'organicthemes'), __("% Comments", 'organicthemes'));
    				?></p>

    My problem is I don’t know how to approach it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The basics for using if() statements like that is that it’s always easier (and a lot safer) to include the ending part as well. I know that it’s possible to leave it off, but it’s a very eays way to run into big issues if somethings not 100% right.

    You’d need to use something like this…

    <?php if (!in_category(array('bishop-column','bishops-blog'))): ?>
    	<p>Your code in here...</p>
    <?php endif; ?>

    One word of advice too – check the quotes that you’re using because you’ll break the JavaScript call if you use ” ‘s inside other ” ‘s without proper escaping. If it was me, I’d set up an external JavaScript file and use that to handle the JS side of things.

    Thread Starter dprogramb

    (@dprogramb)

    Thanks so much, catacaustic! Works like a charm.

    Thread Starter dprogramb

    (@dprogramb)

    Thanks also for the tip on the endif and the quotes!

    That’s all good. It always takes time to learn new things like this, so any help that you can get along the way is always a bonus.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘HTML inside PHP’ is closed to new replies.