Hey there! This question may be pretty complex since we have a lot going on here, but here it is. I have a CPT and I originally built the single-cpt.php template to display the single CPT page. I have since upgraded to utilizing PRO LAYOUTS to render the single CPT page and it looks great. Here’s the issue I’m running into, I’m running what I call “virtual pages” as a child of the single CPT page.
Examples:
domain.com/cpt/single-cpt/ - that’s the regular single-cpt.php layout (or PRO Layouts)
domain.com/cpt/single-cpt/specials/ - that’s the “virtual page” I’m running as a child of the single CPT page.
This worked when I used single-cpt.php to output the single page but now it seems that PRO Layouts is no longer allowing me to use the virtual child page. Instead it’s just outputting the LAYOUT.
Here’s how I’m handling the child page:
public function load_filters() {
add_filter('rewrite_rules_array', [$this, 'fsp_insertrules']);
add_filter('query_vars', [$this, 'fsp_insertqv']);
remove_filter('wp_head', [$this, 'rel_canonical']);
add_filter('wp_head', [$this, 'fsp_rel_canonical']);
}
...
/**
* Rules for Pages and rewrite rules
*
* @param $rules
*
* @return $rules
*/
public function fsp_insertrules($rules) {
$newrules = array();
foreach (BM_Studio_Pages::$VIRTUAL_PAGE_SLUGS as $slug => $title) {
$newrules['locations/([^/]+)/' . $slug . '/?$'] = 'index.php?locations=$matches[1]&fpage=' . $slug;
}
return $newrules + $rules;
}
/**
* Tell WordPress to accept our custom query variable
*
* @param $vars
*
* @return $vars
*/
public function fsp_insertqv($vars) {
array_push($vars, 'fpage');
return $vars;
}
/**
* Remove WordPress's default canonical handling function
*
* @return string
*/
public function fsp_rel_canonical() {
global $current_fp, $wp_the_query;
if (!is_singular()) {
return;
}
if (!$id = $wp_the_query->get_queried_object_id()) {
return;
}
$link = trailingslashit(get_permalink($id));
// Make sure virtual page permalinks are canonical
if (!empty($current_fp)) {
$link .= user_trailingslashit($current_fp);
}
echo '<link rel="canonical" href="' . $link . '" />';
}
THEN, in my single-cpt.php file, I would call the various templates as such:
$current_fp = get_query_var('fpage');
if ($current_fp == 'specials' ) {
x_get_view('studio', 'promo');
}
Wondering how I can get this to work with layouts. I don’t necessarily need LAyouts to be used for the virtual child page (though if it could, that would be AWESOME!) but I definitely need to be able to point the virtual page ($current_fp === 'specials') to a different PHP template. Is there a filter that runs before LAYOUTS init’s on the page to decide if the LAYOUT is used or if I can point to a different spot?
Thank you!