Archive Templates And ACF – No Data For Field
When you use Oxygen Builder, it’s easy and convenient to create one archive page template that can, in one go, cater for all category and tag pages. I’ve just created such a template for my husband’s work blog. He writes a lot of blog posts and uses categories and tags extensively to organise the various topics.
In order to make each archive page make more sense to visitors, I wanted to add a large descriptive paragraph at the top of each category or tag archive page to properly introduce the list of blog posts underneath. You can of course do this in Oxygen Builder and WordPress by using the built-in tag or category Name and Description fields.
Using Built-In Archive Name And Description Fields
But when the built-in name and description fields are specified on each category or tag page, and then inserted into an Oxygen template via a dynamic field, the archive page title of say, “Category: Cakes” instead of just “Cakes“. To get rid of the “Category:” part of the title you have to create and run a PHP function.
Further, if you use the description field as your text “topper” for each archive page, then any text supplied is unformatted. All useful HTML will have been stripped.
Use Advanced Custom Fields Instead
It makes more sense to create your own archive fields using something like ACF. That way you won’t have to deal with removing superfluous text from the title and you’ll be able to have as much HTML in the description as you want.
The fields you specify can then be queried dynamically from within Oxygen. However this is not as straightforward when working with archives as it is when say, working with posts or pages. To get it working you need to do the following:
Install Scripts Plugin
Install a scripts plugin. I use WPCodeBox – it’s one of my must-have plugins.
Add ACF Fields
Add two ACF fields to category and tag pages, called Archive Title and Archive Description.
Supply ACF Values
Supply values for each field on every category and tag page. So you would give every tag and category page its own title and description.
Add PHP
Add two PHP functions, one to return the archive title field and the other to return the archive description field.
Create Template
Create an Oxygen Builder template that applies only to tag and archive pages and design it to your liking.
At the top of the Oxygen Builder template add a title and double click it to reveal the insert data button, where you can then specify a dynamic value. Supply the dynamic data by clicking on PHP Function Return value in the advanced section. In the function name field, type the name of your function that retrieves the archive title, (supply just the function name without the brackets). For example I entered get_archive_title
Next add a paragraph to the template and double click it to reveal the insert data button. Supply the dynamic data by clicking on PHP Function Return value in the advanced section. In the function name field, type the name of your function that retrieves the archive description. Again, supply just the function name without the brackets. For example I entered get_archive_description.