Home › Forums › Add-ons › Repeater Field › Different styling of posts inside a repeater using relational content
Hi there,
I have a fairly complicated problem and my current skills in PHP are not advanced enough so I thought I’d ask here.
I’m making a website for an event and I’m using the repeater field along with relational content to build the schedule of the event.
Basically I call the name of the speaker, the name of the talk and they all display neatly on my schedule page.
My problem is that I’d like to display certain events in a lighter way: I don’t need the name of the speaker nor the link to the speak summary. And I’d like to style those events (the breaks) a bit differently.
What I’d like to do is:
if it’s a break
-> show the name (breakfast, coffee break, etc.)
if it’s something else
-> show the picture of the speaker, her name, her twitter account, the name of the talk, the link to the talk summary, etc.
You can see exactly what I aim to do here: http://2014.uxlausanne.com/schedule
It’s the 2014 website which was static and I’m trying to build the 2015 website on WP.
You’ll see that, for example, the breakfast on Thursday is in light grey, no links and no pictures while the first talk is bolder, has a link to the talk summary and has various infos about the speaker.
If this might help, here’s the current code of each “event”:
<!-- THURSDAY EVENTS 1ST SESSION -->
<?php // check if the repeater field has rows of data
if( have_rows('thursday_events_1st_session') ):?>
<?php // loop through the rows of data
while ( have_rows('thursday_events_1st_session') ) : the_row(); ?>
<div class="container isolated schedule">
<div class="row">
<div class="col-sm-3 col-xs-12">
<?php $posts = get_sub_field('event');?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<h3 class="unbold"><?php the_field('start_time'); ?> – <?php the_field('end_time'); ?></h3>
</div>
<div class="col-sm-6 col-xs-12">
<h3><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?>: <a href="#"><?php the_title(); ?></a></h3>
<small><?php the_field('event_location'); ?></small>
<hr class="short">
<p><?php the_excerpt(); ?></p>
</div>
<div class="col-sm-3 col-xs-12">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail( 'speaker-thumbnail', array( 'class' => 'img-thumbnail' ) ); ?>
</a>
<?php endif; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endforeach; ?>
<?php $posts = get_sub_field('speaker');?>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail( 'speaker-thumbnail', array( 'class' => 'img-thumbnail' ) ); ?>
</a>
<?php endif; ?>
<h5 class="text-stronger"><?php the_title(); ?></h5>
<p><?php if(get_field('twitter_profile')) { echo '<a href="https://twitter.com/' . get_field('twitter_profile') . '">@' . get_field('twitter_profile') . '</a>'; } ?></p>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endforeach; ?>
</div>
</div>
</div>
<div class="container"><hr class="light"></div>
<?php endwhile;
else : // no rows found ?>
<?php endif; ?>
<div class="container"><hr></div>
<!-- /THURSDAY EVENTS 1ST SESSION -->
Thanks in advance for your help!
Loris
You must be logged in to reply to this topic.
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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.