Home › Forums › Add-ons › Repeater Field › Styling subfields
I’d like to apply styling to the individual sub-fields. Example H3 on the Position for each repeater, while also ensuring that each row stays seperate from the next. I’ve done that now with just a p tag, but I would like also to know if there’s a better way. This is being added to my functions file.
//* Add Current Officer Meta to Current Officers Page
add_action( 'genesis_entry_header', 'ogs_current_officer', 12 );
function ogs_current_officer($post_meta) {
if ( is_page ( 'officers-trustees' ) ) {
// check if the repeater field has rows of data
if( have_rows('officer_or_trustee') ):
echo '<p>';
// loop through the rows of data
while ( have_rows('officer_or_trustee') ) : the_row();
// display a sub field value
the_sub_field('position');
the_sub_field('name');
the_sub_field('term_years');
the_sub_field('co_org');
the_sub_field('phone');
echo '</p>';
endwhile;
else :
// no rows found
endif;
}}
I figured it out. My solution is below if anyone else wants to see it.
//* Add Past Officer Group Meta to Past Officers Page
add_action( 'genesis_entry_header', 'ogs_past_officers', 12 );
function ogs_past_officers($post_meta) {
if ( is_page ( 'past-officers' ) ) {
if( have_rows('add_past_officer_group') ):
while( have_rows('add_past_officer_group') ): the_row();
// vars
$term_years = get_sub_field('term_years');
$po_president = get_sub_field('po_president');
$po_vp = get_sub_field('po_vp');
$po_vp_1 = get_sub_field('po_vp_1');
$po_vp_2 = get_sub_field('po_vp_2');
$po_secretary = get_sub_field('po_secretary');
$po_treasurer = get_sub_field('po_treasurer');
echo '<p>';
if( $term_years):
echo '<b>Term Years:</b> ' . get_sub_field('term_years'). '';
endif;
if( $po_president ):
echo '<b>President:</b> ' . get_sub_field('po_president'). '';
endif;
if( $po_vp ):
echo '<b>Vice President:</b> ' . get_sub_field('po_vp'). '';
endif;
if( $po_vp_1 ):
echo '<b>1st Vice President:</b> ' . get_sub_field('po_vp_1'). '';
endif;
if( $po_vp_2 ):
echo '<b>2nd Vice President:</b> ' . get_sub_field('po_vp_2'). '';
endif;
if( $po_secretary ):
echo '<b>Secretary:</b> ' . get_sub_field('po_secretary'). '';
endif;
if( $po_treasurer ):
echo '<b>Treasurer:</b> ' . get_sub_field('po_treasurer'). '';
endif;
echo '</p>';
echo $content;
endwhile;
endif;
}}
The topic ‘Styling subfields’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.