Skip Navigation

[Resolved] Custom header and footer to archive pages

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 6 replies, has 2 voices.

Last updated by Franco Calcagni 5 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1365261

We need to create a custom page template for taxonomy pages where we have a specific header and footer (we need this because some catagories will have the header in english and others in italian).
We saw that the content template can do that but the header and footer are repeating for every piece of content in the loop.

#1365411

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I don't understand from your question how you are creating your custom header and footer.

Are you editing the theme PHP template files?

In particular I'm puzzled by "we saw that the content template can do that", because Content Templates only replace what is output by the_content() in the PHP templates, and are not used for headers or footers.

#1365419

Hi Nigel,
for example, for the PAGES of the site we created a content template that holds also the header and footer in the content area so since the template holds that data we can easily create a template with a different header or footer.
This doesn't work for the archive pages because if we build a content template to be applied to a taxonomy page and place the DIV of header and footer, this repeats for every element of the page.

#1365463

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

So you edited the theme template files so that they output no header and no footer, so the content template takes up the whole page because there is no conventional header or footer, and your content template can include a fake-header and fake-footer, which you can change as required.

I'll repeat that content templates simply replace what is output by the_content() function in your theme PHP files.

On an archive, the_content() is output for every result of the archive, so, yes, if your template includes a fake header and footer, these will be output for every item in the archive loop.

You could edit the relevant archive.php template and insert a specific content template before the loop and another specific content template after the loop, and then design those templates using Toolset how you like.

To output a content template within a PHP template you can use the render_view_template API function: https://toolset.com/documentation/programmer-reference/views-api/#render_view_template

#1365471

Thanks Nigel, but in this way I get the result of a custom header and footer but I cannot have a specific header or footer depending on the taxonomy, since the archive.php file still remain a unique file.
How can I achieve to get a specific archive file depending on taxonomy? Or a specific template file depending on taxonomy to be recalled by the unique archive.php file?

#1365485

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I expected that you would use the WordPress template hierarchy for this: https://developer.wordpress.org/themes/basics/template-hierarchy/ or hidden link

archive.php is the most generic template for archives if there isn't a more specific one that matches the page being loaded.

So if you wanted a special template to only be used for the 'red' term of the 'colour' taxonomy then you could create a template file taxonomy-colour-red.php which would be used in place of the next most specific template available for that page.

An alternative would be to add conditional shortcodes to your templates where you insert the header and footer to show different content according to the taxonomy term of the current archive, for example, although using the built-in template hierarchy would be more efficient if you are already editing the theme template files.

#1365495

OK NIgel thanks I will try to do in that way using the template hyerarchy.

Best,