Community Forums › Forums › Archived Forums › General Discussion › Desperately need help with custom loop in archive
Tagged: ACF, Custom fields, custom loop
- This topic has 6 replies, 2 voices, and was last updated 7 years, 4 months ago by
photoaddictsa.
-
AuthorPosts
-
September 22, 2017 at 11:18 am #211757
photoaddictsa
MemberHi,
I'm still learning here, decided to give a custom loop a try.
I've got the loop displaying the info I wanted but the code output is all wonky.
Here is the whole code: (I'm using ACF)
<?php remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'your_custom_loop' ); // Remove custom structural wraps. remove_action( 'genesis_before_content_sidebar_wrap', 'studio_wrap_open', 6 ); remove_action( 'genesis_after_content_sidebar_wrap', 'studio_wrap_close', 13 ); function your_custom_loop() { if(have_posts()) : while(have_posts()) : the_post(); echo '<article class="entry">'; echo '<div class="entry-content">'; echo '<div class="won_by">'; get_field('team_won_by_x_runs'); echo '</div>'; echo '<ul class="tvst">'; echo '<li class="team1">'; echo '<img src="' . get_field('team_1_photo') . '" alt="" />'; echo '<span class="runswwickets">' . get_field('team_1_runs_wickets') . '</span>'; echo '</li>'; echo '<li class="vs">'; echo '<h3 class="teamname">' . get_field('team_1') . '</h3>'; echo '<em class="vs">' . VS . '</em>'; echo '<h3 class="teamname">' . get_field('team_2') . '</h3>'; echo '<div class="date-venue">'; echo '<div class="date">'; get_field('date'); echo '<em>(GMT+2)</em>'; echo '</div>'; echo '<div class="venue">'; get_field('venue'); echo '</div>'; echo '</li>'; echo '<li class="team2">'; echo '<img src="' . get_field('team_2_photo') . '" alt="" />'; echo '<span class="runswwickets">' . get_field('team_2_runs_wickets') . '</span>'; echo '</li>'; echo '</ul>'; echo '</div>'; echo '</div>'; echo '</article>'; endwhile; endif; } genesis();
This the output:
One is inside <main and other is not, where did I mess up?
http://nmbstars.co.za/nmbs/fixtures/September 22, 2017 at 11:35 am #211758Brad Dalton
ParticipantSeptember 22, 2017 at 1:17 pm #211761photoaddictsa
MemberThanks for the advice Brad, here is the gist link: https://gist.github.com/photoaddictsa/2343851119a91523940de538a831ac57
September 25, 2017 at 2:00 am #211835Brad Dalton
ParticipantSeptember 26, 2017 at 4:56 am #211866photoaddictsa
MemberFigured it out, I was over thinking the whole thing a bit.
Working through some of your other tutorials actually helped me figure it out 🙂
September 26, 2017 at 5:27 pm #211879Brad Dalton
ParticipantCool. 2 things you might want to consider :
1. Use get_post_meta in replace of get_field
2. Use class_exists to check ACF is active
September 26, 2017 at 11:45 pm #211908photoaddictsa
MemberAh ok, awesome! Thanks very much.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.