Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to display ACF fields with category posts
Tagged: ACF, Custom fields, genesis_get_custom_field, get_post_meta
- This topic has 22 replies, 3 voices, and was last updated 7 years, 5 months ago by Bart van Maanen.
-
AuthorPosts
-
September 30, 2016 at 11:15 am #193997Brad DaltonParticipant
Just wrap it in a div like this:
add_action( 'genesis_entry_content', 'custom_field_credits' ); function custom_field_credits() { if ( ! is_single() && in_category( 'films' ) ) return; $title = genesis_get_custom_field( 'title' ); $product = genesis_get_custom_field( 'product' ); echo'<div class="content-box-red">'; if ( $title ) { printf( '<div class="credits">%s</div>', $title ); } if ( $product ) { printf( '<div class="credits">%s</div>', $product ); } echo'</div>'; }
Then add the CSS for the colored content boxes
October 3, 2016 at 10:35 am #194163Bart van MaanenParticipantHi Brad,
Lost you on Friday because we're in a different time zone.So, I now got this code working, only styled with a strong heading:
add_action( 'genesis_entry_content', 'credits' ); function credits() { if ( ! is_single() && in_category( 'films' ) ) return; $titel = get_post_meta( get_the_ID(), 'titel', true ); if( ! empty( $titel ) ) { echo '<strong><div class="credits">'. $titel .'</strong></div>'; } $productie = get_post_meta( get_the_ID(), 'productie', true ); if( ! empty( $productie ) ) { echo '<div class="credits">'. $productie .'</div>'; } $regie = get_post_meta( get_the_ID(), 'regie', true ); if( ! empty( $regie ) ) { echo '<div class="credits">'. $regie .'</div>'; } }
Then I tried the printf code above with the div for a content box, like this:
add_action( 'genesis_entry_content', 'credits' ); function credits() { if ( ! is_single() && in_category( 'films' ) ) return; $titel = genesis_get_custom_field( 'titel' ); $productie = genesis_get_custom_field( 'productie' ); $regie = genesis_get_custom_field( 'regie' ); echo'<div class="content-box-red">'; if ( $titel ) { printf( '<div class="credits">%s</div>', $titel ); } if ( $productie ) { printf( '<div class="credits">%s</div>', $productie ); } f ( $regie ) { printf( '<div class="credits">%s</div>', $regie ); } echo'</div>'; }
That returned a white screen I'm afraid.
I replaced it with the get_post_meta code again and tried to style it withecho'<div class="content-box-red">'; echo'</div>';
But then only the title ( 'titel' ) was in the content-box-red settings.
Any idea why the code with genesis_get_custom_fields won't do it?
October 13, 2016 at 5:58 am #194636Bart van MaanenParticipantHi Brad, and everybody else interested,
I combined some code from Brad to show ACF fields for a specific category and the show up as intended. But the styling - a content box - shows up empty on all post and pages, though the code should address the category 'films' only. The printf method didn't seem to be working.
The site is over here: http://www.mokumfilm.nl/
Now in functions.php is the following code:
//* Maak Advanced Custom Fields Film Credits zichtbaar voor categorie Films add_action( 'genesis_entry_content', 'credits' ); function credits() { if ( ! is_single() && in_category( 'films' ) ) return; echo'<div class="content-box-red">'; $titel = get_post_meta( get_the_ID(), 'titel', true ); if( ! empty( $titel ) ) { echo '<div class="credits">'. $titel .'</div>'; } $regie = get_post_meta( get_the_ID(), 'regie', true ); if( ! empty( $regie ) ) { echo '<div class="credits">'. ' Regie: ' . $regie .'</div>'; } $scenario = get_post_meta( get_the_ID(), 'scenario', true ); if( ! empty( $scenario ) ) { echo '<div class="credits">'. ' Scenario: ' . $scenario .'</div>'; } $camera = get_post_meta( get_the_ID(), 'camera', true ); if( ! empty( $camera ) ) { echo '<div class="credits">'. ' Camera: ' . $camera .'</div>'; } $geluid = get_post_meta( get_the_ID(), 'geluid', true ); if( ! empty( $geluid ) ) { echo '<div class="credits">'. ' Geluid / sound design: ' . $geluid .'</div>'; } $muziek = get_post_meta( get_the_ID(), 'muziek', true ); if( ! empty( $muziek ) ) { echo '<div class="credits">'. ' Muziek: ' . $muziek .'</div>'; } $montage = get_post_meta( get_the_ID(), 'montage', true ); if( ! empty( $montage ) ) { echo '<div class="credits">'. ' Editor: ' . $montage .'</div>'; } $producent = get_post_meta( get_the_ID(), 'producent', true ); if( ! empty( $producent ) ) { echo '<div class="credits">'. ' Producent: ' . $producent .'</div>'; } $cast = get_post_meta( get_the_ID(), 'cast', true ); if( ! empty( $cast ) ) { echo '<div class="credits">'. ' Met: ' . $cast .'</div>'; } echo'</div>'; }
Your tips and advice are greatly appreciated. Thanks Bart
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.