To create a WordPress page template with ACF (Advanced Custom Fields) fields, you can follow these steps:
1. Install and activate the Advanced Custom Fields plugin.
2. Create a new field group and add the fields you want to include in the template.
3. Create a new file in your theme's directory and name it page-template.php.
4. Add the following code at the top of the file, replacing "Template Name" with the name you want to give to your template:
<?php
/*
Template Name: Your Template Name
*/
5. Add the code to output the ACF fields in the template. You can use the get_field() function to retrieve the values of the fields you created. For example, if you have a text field named "subtitle", you can output its value like this:
<?php echo get_field('subtitle'); ?>
6. You can also use a loop to display dynamic content, such as a list of items stored in a repeater field. Here's an example of how to loop through a repeater field named "items":
<?php if( have_rows('items') ): ?>
<ul>
<?php while( have_rows('items') ): the_row();
// vars
$item_title = get_sub_field('item_title');
$item_description = get_sub_field('item_description');
?>
<li>
<h3><?php echo $item_title; ?></h3>
<p><?php echo $item_description; ?></p>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
7. Finally, add the template to your pages by going to the page editor and selecting it from the "Page Attributes" template dropdown.