Home › Forums › Front-end Issues › beginner question (acf dont show on frontpage)
I need to register something in funcitions.php or just use the code on page?
(admin image: https://i.imgsafe.org/e45b6189a1.png )
and in my homepage I put the code:
<div class="container">
<div class="row">
<?php
// TO SHOW THE PAGE CONTENTS
while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
<div class="entry-content-page">
<?php the_content(); ?> <!-- Page Content -->
</div><!-- .entry-content-page -->
<?php
endwhile; //resetting the page loop
wp_reset_query(); //resetting the page query
?>
<?php if( have_rows('repeater_slides') ): ?>
<ul>
<?php while( have_rows('repeater_slides') ): the_row(); ?>
<li>sub_field_1 = <?php the_sub_field('imagem'); ?>, sub_field_2 = <?php the_sub_field('titulo_do_slide'); ?>, etc</li>
<?php
$sub_field_3 = get_sub_field('sub-titulo');
// do something with $sub_field_3
?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</div>
</div>
</div>
Hi @royroy2
The repeater loop needs to be called within the main loop have_posts() that you have on the page. Within here:
<?php
// TO SHOW THE PAGE CONTENTS
while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
<div class="entry-content-page">
<?php the_content(); ?> <!-- Page Content -->
</div><!-- .entry-content-page -->
<?php
endwhile; //resetting the page loop
wp_reset_query(); //resetting the page query
?>
Thank’s for the help, but dont work =/
sorry, but it’s my first wp theme.
<div class="container">
<div class="row">
<?php
// TO SHOW THE PAGE CONTENTS
while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
<div class="entry-content-page">
<?php if( have_rows('repeater_slides') ): ?>
<ul>
<?php while( have_rows('repeater_slides') ): the_row(); ?>
<li>sub_field_1 = <?php the_sub_field('imagem'); ?>, sub_field_2 = <?php the_sub_field('titulo_do_slide'); ?>, etc</li>
<?php
$sub_field_3 = get_sub_field('sub-titulo');
// do something with $sub_field_3
?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php the_content(); ?> <!-- Page Content -->
</div><!-- .entry-content-page -->
<?php
endwhile; //resetting the page loop
wp_reset_query(); //resetting the page query
?>
</div>
</div>
</div>
Hi @royroy2
It depends on where you assign the custom fields (location rules).
If you set it to a post/page, then you need to pass that post/page ID to the have_rows()
function like this:
<?php if( have_rows('repeater_slides', 99) ): ?>
<?php while( have_rows('repeater_slides', 99) ): the_row(); ?>
Where “99” is the post/page ID.
Also, could you please share the JSON export file of your field group so I can check your setup?
Thanks 🙂
Again, thanks a lot for your help @James
my JSON
[
{
"key": "group_587d7490be979",
"title": "Slides Home",
"fields": [
{
"sub_fields": [
{
"return_format": "array",
"preview_size": "full",
"library": "all",
"min_width": "",
"min_height": "",
"min_size": "",
"max_width": "",
"max_height": "",
"max_size": "",
"mime_types": "",
"key": "field_587d74d758b8f",
"label": "Imagem",
"name": "imagem",
"type": "image",
"instructions": "Imagem",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
}
},
{
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": "",
"key": "field_587d74ee58b90",
"label": "T\u00edtulo do Slide",
"name": "titulo_do_slide",
"type": "text",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
}
},
{
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": "",
"key": "field_587d750658b91",
"label": "Sub-titulo",
"name": "sub-titulo",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
}
},
{
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": "",
"key": "field_587d751358b92",
"label": "Texto",
"name": "texto",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
}
},
{
"default_value": "",
"placeholder": "",
"key": "field_587d752158b93",
"label": "Bot\u00e3o",
"name": "botao",
"type": "url",
"instructions": "URL",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
}
}
],
"min": 0,
"max": 0,
"layout": "block",
"button_label": "Adicionar Slide",
"collapsed": "",
"key": "field_587d749958b8e",
"label": "Slides",
"name": "slides",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
}
}
],
"location": [
[
{
"param": "page",
"operator": "==",
"value": "81"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"description": ""
}
]
Hi @royroy2
Based on your location rule, your field group is assigned to a page with the ID of “81”. In this case, you should be able to use the following code:
<?php if( have_rows('repeater_slides', 81) ): ?>
<?php while( have_rows('repeater_slides', 81) ): the_row(); ?>
I hope this helps 🙂
@James thanks again…
but when I try to put in my loop I got a error
Parse error: syntax error, unexpected end of file
<?php
while ( have_posts() ) : the_post(); ?>
<div class="entry-content-page">
<?php the_content(); ?>
</div>
<?php
endwhile; //resetting the page loop
wp_reset_query(); //resetting the page query
?>
Where can I inclute the ACF code ?
(if it dont ask to much)
Hi @royroy2
Based on your code, you should be able to do it like this:
<div class="container">
<div class="row">
<?php
// TO SHOW THE PAGE CONTENTS
while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
<div class="entry-content-page">
<?php the_content(); ?> <!-- Page Content -->
</div><!-- .entry-content-page -->
<?php
endwhile; //resetting the page loop
wp_reset_query(); //resetting the page query
?>
<?php if( have_rows('repeater_slides', 81) ): ?>
<ul>
<?php while( have_rows('repeater_slides', 81) ): the_row(); ?>
<li>sub_field_1 = <?php the_sub_field('imagem'); ?>, sub_field_2 = <?php the_sub_field('titulo_do_slide'); ?>, etc</li>
<?php
$sub_field_3 = get_sub_field('sub-titulo');
// do something with $sub_field_3
?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</div>
</div>
</div>
I hope this helps 🙂
The topic ‘beginner question (acf dont show on frontpage)’ 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.