This code enables you to add custom field content like text, HTML & images to the Genesis loop. You can use the code 2 ways:
- The 1st snippet of code can be added directly to any template file which uses the WordPress Template Hierarchy. See 1st snippet below which includes the code for adding custom fields content to a archive loop.
- You can also use the code in your functions file with any conditional tag added after the function name. See 2nd code snippet below.
- And you can create a custom archive template file and only output specific content in replace of the default content displayed on standard archives
The code also works when using the Genesis Portfolio Pro plugin to generate a CPT named portfolio.
1st Snippet
Use the WordPress Template Hierarchy to name your template file so its loaded on specific archive page types like category, tag, author, custom post type & taxonomy archive page types.
Using a code editor, create a new file in your child themes root directory and add the code below to the file.
2nd Snippet
For use in genesis child themes functions file with conditional tag
ACF Check
When using a plugin for your custom field input, make sure you include a check to make sure the plugin is active like this :
if ( ! class_exists( 'acf' ) )
return;
Pagination
Pagination is set using the default Reading settings for posts per page. You can override these settings using code in your functions file like this:
add_action('pre_get_posts', 'posts_per_cpt_archive_page');
function posts_per_cpt_archive_page( $query ) {
if ( ! is_post_type_archive( 'portfolio' ) )
return;
$query->set( 'posts_per_page', 1 );
return;
}
The above code sets the posts per page at 1 for the portfolio archive. Swap out the conditional tag is_post_type_archive
to target your archive page type.
Custom Field Archive Template File
Name your file using the WordPress Template Hierarchy and add the following code.
Demo Video – Category Archive Loop
The demo video shows how HTML for a image has been added to the value field for a custom field named key. Swap out key with the name of your custom field.
The image has been added to the category archive loop for the category named demo.
You can also use this solution to add custom field content to a custom post type loop.
Demo Video – CPT Archive Loop
The video shows you how to add custom field content a custom post type archive loop named portfolio. It also explains how to display pagination and override the default pagination settings using pre_get_posts.
Learn more : Beginners guide to using custom fields.
Was This Tutorial Helpful?