Tagged: ,

Viewing 2 reply threads
  • Author
    Posts
    • #3592
      liquidws
      Member

      The more I learn piklist, the more I like it! 🙂

      Quick question.. everything I see in regards to conditionals it for admin-pages, what about for frontend. For example, below.. I can check to see if the user added data to the field, if so, it shows on front end, if not code does not display. Love to see a sample or two on how to do this.

      1) basic if and
      2) an if/else statements

      <?php if( get_field('image') ): ?>
         <img src="<?php the_field('image'); ?>" />
      <?php endif; ?>

      * no rush on this. I just looked around the User Guide, and searched forums and seems to be limited info on displaying on front end. Thanks in advance!

    • #3599
      jcrist
      Member

      Since Piklist does thing the WordPress way, you would use get_post_meta(). get_field() on the other hand is a function only available in ACF.

      <?php $image = get_post_meta(get_the_ID(),'image',true);
      
      if( !empty($image) ) : ?>
          <img src="<?php echo $image; ?>" alt="" />
      <?php endif; ?>
    • #3601
      Steve
      Keymaster

      @liquidws– I’m guessing your an ACF convert since you posted the ACF custom function get_field. The way ACF works you need to use their custom functions… but not with Piklist. Since Piklist does everything the WordPress way, you would just use a standard WordPress function.

      For example, if you’re checking to see if this field exists on a post you would use the standard WordPress function get_post_meta:

      <?php $image = get_post_meta(get_the_ID(), 'image', true ); ?>
      
      <?php if($image): ?>
         <img src="<?php echo $image; ?>" />
      <?php endif; ?>
Viewing 2 reply threads
  • You must be logged in to reply to this topic.