Any way to call/load Cloud Library template from PHP files/templates?

Posted in: Newspaper
Post count: 24

Hi all,

we have another situation where we’re unsure how to proceed.

Basically, we have 2 Cloud Templates for author archives (Template1, Template2). Template1 is used as a default author archive template (pagename.com/author/id) while we want to use Template2 when users visit a custom page (pagename.com/columnist/id).

We cannot achieve this through the theme options because if we manually select the template to use for specific author then regardless of if the users visit /author/id or /columnist/id the same template will be used.

Is there a way to achieve this by calling a specific Cloud Template in the code when users visit the /columnist/id page? We got the redirects down in the PHP code but can’t seem to find a way to override the Cloud template used on the custom url.

By using the add_filter('author_template', 'custom_author_template_columnist');and inside the custom_author_template_columnist function we can see that template being called here by default is /themes/Newspaper/author.php but by changing this template nothing happens, because the priority of the templates being used it’s probably overwritten by Cloud Library or Composer plugin.

Further inspection using Query Monitor plugin we can see that template being called is wp-content/plugins/td-cloud-library/wp_templates/tdb_view_author.php but can’t seem to find a way to re-use that code in our child theme’s nor our custom plugin’s code where we have our custom blocks/modules setup.

We don’t mind hardcoding the template in php if programatically calling the Cloud Template is not possible.

Any help here would be appreciated.

Thanks!

  • This topic was modified 1 year by mm-2.
Post count: 24

Managed to get this sorted after digging through Composer and Cloud Library plugins’ code.

Here’s the code snippet:

add_filter('author_template', 'columnist_custom_author_template', 99999);

function columnist_custom_author_template($default_template) {
global $wp;
// 1. Check if it's actually an author archive
// 2. Check the matched_rule to see if it's the columnist rule
if (is_author() && isset( $wp->matched_rule ) && '^columnist/([^/]+)/?$' === $wp->matched_rule) {
apply_filters('td_single_override', id); // COLUMNIST Cloud Library's Cloud Template ID (integer)
}
// Otherwise, return the default template (which might load template from TagDiv’s normal assignment)
return $default_template;
}

The important bit is
apply_filters('td_single_override', id);
where the second parameter is TagDiv Cloud Library’s Cloud Template ID (integer).

Viewing 2 posts - 1 through 2 (of 2 total)
The forum ‘Newspaper’ is closed to new topics and replies.