Skip Navigation

[Resolved] Enabling Custom Archive Options

This support ticket is created 5 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 5 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1374897
Screenshot 2019-11-02 at 13.14.07.png

I am currently writing a new theme and will be using Toolset CPTs and Archive pages set up by Toolset.

An example of the format the theme will follow is at hidden link. This is the archive page (set up with Toolset) for the 'Vessels' CPT. In this instance, I have used Layouts to manually add the H1 heading and the paragraph of text below it (see attached image).

In the new theme, this section of the page should be output by the theme NOT Layouts, so I'd like the option for these text sections to be set on the backend for each CPT Archive. I could potentially use the 'archive description' field for one section of text, but that only gives me one field to use, not two.

Is there a way to enable custom fields/settings for an archive page, or is there another potential solution you could suggest?

Thanks in Advance!

#1375123

Hi, the archive description field is one built-in way to store archive-specific information. I'm not aware of another easy way to add arbitrary archive-specific information like this, or a way to add more archive-specific fields to the wp-admin interface. A few other ideas that might be helpful in this case:

1. Use Toolset's Content Templates to store and display this archive-specific information. You could create an unassigned Content Template for each possible archive, and add the title and introductory text for that archive in the Content Template. Then render the appropriate Content Template with PHP in each archive template PHP file: https://toolset.com/documentation/programmer-reference/views-api/#render_view_template
Obviously this means the content is managed in wp-admin, but it's not in Layouts. It's in Content Templates. I'm not sure based on your description if this is appropriate or not.

2. Or instead of creating one Content Template for each archive, you could use a single Content Template with conditional HTML that tests the archive title and displays the corresponding title and text. That would probably be easier to maintain in the long run, but more difficult to set up initially, compared to option 1. https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-archive-title

3. Use custom code to store each archive's title and text as theme options. You may also create a theme options page where these text strings can be managed in wp-admin. This option is outside the scope of Toolset, so I won't be able to provide much more than links to the WordPress documentation for some theme options APIs.

Let me know if you have questions about these alternative options, and I can provide additional feedback.

#1377057

Hi Christian,

Thanks for your advice, I have gone for option 3 and created a wp-admin options page for my custom settings, so I understand your support will be limited on this.

1. I created an array of all active CPTs
2. I created a foreach loop to iterate over each CPT
3. I placed both the add_settings_section() and add_settings_field() sections of the code within the foreach loop
3. Those settings defined in the loop call to functions outside the loop that then perform the saving to the database etc.

It's tested and working, with the new settings then used to filter both get_the_archive_title() and get_the_archive_description().

At this stage I only have two questions
1. Is it good practice to create settings using a loop like this?
2. Given that I will always be using these customisations alongside Toolset, would you advise creating the settings page via the theme or via a custom plugin? Right now I have done it via a custom plugin.

#1377135

1. Is it good practice to create settings using a loop like this?
Seems okay, as long as you are including some conditional logic to prevent errors if a post type does not exist for some reason.

2. Given that I will always be using these customisations alongside Toolset, would you advise creating the settings page via the theme or via a custom plugin?
I don't have an opinion here, either could be fine. I guess it depends on how you want to reuse this theme and plugin across different sites.