- This topic has 2 replies, 3 voices, and was last updated 6 years, 10 months ago by
Steve.
-
AuthorPosts
-
-
April 8, 2015 at 4:35 pm #3592
liquidwsMemberThe 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!
-
April 9, 2015 at 9:08 am #3599
jcristMemberSince 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; ?> -
April 9, 2015 at 9:20 am #3601
SteveKeymaster@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; ?>
-
-
AuthorPosts
- You must be logged in to reply to this topic.