WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] custom field, outside loop -- add conditional tag? (1 post)

  1. csleh
    Member
    Posted 5 years ago #

    using this code:

    <div id="sidebar">
    <?php
          $quote = get_post_meta($post->ID, "quote", true);
          //check that we have a custom field
          if ($quote != "")
          {
            {
              echo "<p><em>&quot;$quote&quot;</em></p>";
            }
          }else { echo '<p><em>&quot;And a quote will look like this.&quot;</em></p>
    		  <p>by somebody </p>'; }
    ?>
    <?php $biophoto = get_post_meta($post->ID, 'biophoto', TRUE); ?>
    <?php if($biophoto) { ?><img src="<?php echo $biophoto; ?>" alt="<?php  { echo the_title(); } ?>" /><?php } ?>
    		</div>

    which is working.

    Have since realized it would be better if the quote didn't show on Pages that have biophoto.

    Unfortunately, these are Pages, not posts so I'm having a hard time wrapping my head around how to code this. The Pages with biophoto custom field are all children of another Page, so I could filter by "if child of page 9, then show a biophoto if there is one. If it's any other Page, show the quote"

    I've tried variations of this, but keep getting errors. I don't know php, and suspect the trouble is wrapping php inside other php bits (?)

    Another idea would be to add something to the page template: "if child of page 9, use this alternatesidebar.php, else use sidebar.php" but I'm having trouble with that too.

Topic Closed

This topic has been closed to new replies.

About this Topic