There is a DFD Native theme for wordpress, there is a type of pages - a portfolio. If you create a page with this URL - http://sitename.com/portfolio then when you open this page in the frontend, the archive template for the portfolio is loaded, and you need to load a special template for the portfolio.
This template is selected when creating the page from the side:
enter image description here

And if you create a portfolio page with such a URL - http://sitename.com/portfolio1 , then the correct template for the portfolio is loaded.
What could be the problem?

index.php file in the theme root

 <?php if ( ! defined( 'ABSPATH' ) ) { exit; } get_header(); get_template_part('inc/loop/components/layout'); if(class_exists('Dfd_Layout_Builder')) { new Dfd_Layout_Builder(array( 'loop' => 'loop', 'page' => 'post', 'class' => 'dfd-blog-loop' )); } get_footer(); 

file archive.php in the theme root

 <?php if ( ! defined( 'ABSPATH' ) ) { exit; } $post_type = get_post_type(); if($post_type == 'portfolio') { get_template_part('taxonomy-portfolio'); } elseif($post_type == 'gallery') { get_template_part('taxonomy-gallery'); } else { get_template_part('index'); } 

taxonomy-portfolio.php file in the root of the theme

 get_header(); get_template_part('inc/loop/components/layout'); if(class_exists('Dfd_Layout_Builder')) { new Dfd_Layout_Builder(array( 'loop' => 'loop', 'page' => 'portfolio_archive', 'class' => 'dfd-portfolio-loop' )); } get_footer(); 

here cleaned _archive in the key page , nothing helped.

Dfd_Layout_Builder class

  class Dfd_Layout_Builder { /** @var string Current page type. */ private $page_type = ''; /** * Constructor. * * * @since 1.0 * @access private */ function __construct($args) { $this->page_type = $this->get_page_type(); $defaults = array( 'loop' => 'loop', 'page' => 'page', 'class' => 'no-ttile', ); $args = wp_parse_args($args, $defaults); $this->build_layout($args['loop'], $args['page'], $args['class']); } /** * Get the layout width option value * * @since 1.0 * @access public */ function get_layout_width($page) { $layout_width = DfdMetaBoxSettings::get('dfd_layout_width'); if(!$layout_width || empty($layout_width)) { global $dfd_native; $layout_width = isset($dfd_native[$page.'_layout_width']) ? $dfd_native[$page.'_layout_width'] : 'boxed'; } return $layout_width; } /** * Check if custom header is enabled for current page * * @since 1.0 * @access public */ function get_stunning_header($page) { $stun_header_enabled = DfdMetaBoxSettings::get('dfd_stun_header'); if(!$stun_header_enabled || empty($stun_header_enabled)) { global $dfd_native; $stun_header_enabled = isset($dfd_native[$page.'_stun_header']) ? $dfd_native[$page.'_stun_header'] : 'on'; } if($stun_header_enabled == 'on') { get_template_part('templates/header/stunning-header'); } } /** * Get the default page type to load default settings if no specific options were defined for current page from theme options or page metaboxes * * @since 1.0 * @access public */ function get_page_type() { $page_type = 'pages'; if(is_404()) { $page_type = '404'; } if(is_search()) { $page_type = 'search'; } if(is_single()) { $page_type = 'single'; } if(is_archive()) { $page_type = 'archive'; } return $page_type; } /** * Generate sidebars configuration and * * @since 1.0 * @access public */ function build_sidebar_config($loop, $page, $layout_width) { $item_sidebars = DfdMetaBoxSettings::get('dfd_sidebars_configuration'); if(!$item_sidebars || empty($item_sidebars)) { global $dfd_native; $item_sidebars = isset($dfd_native[$page.'_sidebars_configuration']) ? $dfd_native[$page.'_sidebars_configuration'] : ''; if(!class_exists('Dfd_Theme_Extensions')) { $item_sidebars = '2c-r-fixed'; } } $default = $this->page_type; $sidebars_count = 0; $this->top_dropdowns($page); if($item_sidebars && !empty($item_sidebars)) { switch($item_sidebars) { case '2c-l-fixed': $dfd_layout = 'sidebar-left'; $dfd_width = 'nine'; break; case '2c-r-fixed': $dfd_layout = 'sidebar-right'; $dfd_width = 'nine'; break; case '3c-fixed': $dfd_layout = 'sidebar-both'; $dfd_width = 'six'; break; case '1col-fixed': default: $dfd_layout = 'no-sidebars'; $dfd_width = 'twelve'; } $sidebars_count = (int) substr($item_sidebars, 0, 1) - 1; echo '<div class="blog-section ' . esc_attr($dfd_layout) . '">'; echo '<section id="main-content" role="main" class="' . esc_attr($dfd_width) . ' columns">'; } else { Dfd_Theme_Helpers::set_layout($default, true); } get_template_part('inc/loop/components/loop'); new Dfd_Loop_Builder($loop, $page, $sidebars_count, $layout_width); if($page != 'product_single' && $page != 'shop') { comments_template(); } if(!empty($item_sidebars) && $item_sidebars) { echo ' </section>'; if (($item_sidebars == "2c-l-fixed") || ($item_sidebars == "3c-fixed")) { get_template_part('templates/sidebar', 'left'); echo ' </div>'; } if (($item_sidebars == "2c-r-fixed") || ($item_sidebars == "3c-fixed") || ($item_sidebars == "3c-r-fixed") ) { get_template_part('templates/sidebar', 'right'); } echo '</div>'; } else { Dfd_Theme_Helpers::set_layout($default, false); } } /** * Generate layout and insert sidebars config * * @since 1.0 * @access public */ function build_layout($loop, $page, $class) { $layout_width = $data_atts = ''; $page_type = $this->page_type; $class .= ' '.$page_type; if($page_type == 'pages' || $page_type == 'single' || $page_type == 'archive' || $page_type == '404') { $layout_width .= $this->get_layout_width($page); } $this->get_stunning_header($page); $vc_content_position = DfdMetaBoxSettings::compared($page.'_vc_content_position', ''); $lazy_load_offset = DfdMetaBoxSettings::get('reduce_lazy_load_offset', ''); if($lazy_load_offset && $lazy_load_offset == 'on') { $data_atts .= 'data-lazy-load-offset="1"'; } echo '<section id="layout" class="'.esc_attr($class).'" '.$data_atts.'>'; if($vc_content_position == 'top') { $this->add_composer_content($page); } echo '<div class="row '.esc_attr($layout_width).'">'; $this->build_sidebar_config($loop, $page, $layout_width); echo '</div>'; if($vc_content_position != 'top') { $this->add_composer_content($page); } echo '</section>'; } /** * Generate Visual Composer content for pages where posts, portfolio or gallery content is displayed * * @since 1.0 * @access public */ function add_composer_content($page = 'page') { $avail_templates = array('post', 'portfolio', 'gallery'); if(in_array($page, $avail_templates) && $this->page_type != 'search') { if(have_posts()) { echo '<div class="dfd-content-wrap dfd-vc-content-wrap">'; while (have_posts()) : the_post(); $content = get_the_content(); if(substr_count($content, 'post-password-form') == 0) { the_content(); // Dfd_Theme_Helpers::dfd_link_pages(); echo Dfd_Theme_Helpers::dfd_pagination(); } unset($content); endwhile; echo '</div>'; } } } /** * Generate categories, tags and authors dropdown sorters * * @since 1.0 * @access public */ function top_dropdowns($page) { if(DfdMetaBoxSettings::compared($page.'_cat_tag', 'off') == 'on' && !is_single() && !is_search()) { get_template_part('templates/'.$page, 'top'); } } } 

PS

 add_filter('template_include', 'my_template'); function my_template( $template ) { // если это страница со слагом portfolio, используем файл шаблона page-portfolio.php // используем условный тег is_page() if( is_page('portfolio') ){ $files = array( 'tmp-portfolio.php', 'portfolio.php', 'tmp-page.php', 'tmp-blog.php', ); if ( $new_template = locate_template( $files ) ) return $new_template ; } return $template; } 

    1 answer 1

    connect the page template you need in function.php

    // filter passes the variable $ template - the path to the template file. // By changing this path we change the template file.

     add_filter('template_include', 'my_template'); function my_template( $template ) { // если это страница со слагом portfolio, используем файл шаблона page-portfolio.php // используем условный тег is_page() if( is_page('portfolio') ){ if ( $new_template = locate_template( array( 'page-portfolio.php' ) ) ) return $new_template ; } # шаблон для группы рубрик // этот пример будет использовать файл из папки темы tpl_special-cats.php, // как шаблон для рубрик с ID 9, названием "Без рубрики" и слагом "php" if( is_category( array( 9, 'Без рубрики', 'php') ) ){ return get_stylesheet_directory() . '/tpl_special-cats.php'; } # шаблон для записи по ID // файл шаблона расположен в папке плагина /my-plugin/site-template.php global $post; if( $post->ID == 12 ){ return wp_normalize_path( WP_PLUGIN_DIR ) . '/my-plugin/site-template.php'; } # шаблон для страниц произвольного типа "book" // предполагается, что файл шаблона book-tpl.php лежит в папке темы global $post; if( $post->post_type == 'book' ){ return get_stylesheet_directory() . '/book-tpl.php'; } return $template; } 
    • I added a code to the question that I added to the functions.php file, but nothing has changed. What else can you think of? - word
    • one
      solved the problem, the fact is that the child theme was connected, and it was necessary to throw the desired template into the child theme - word
    • No, all the same, the archive template is loaded. Somehow this topic does not work correctly. The child theme has been disabled, as a result, although the desired template has been selected in the portfolio page, the archive template is loaded. I did not understand why the necessary template stopped working - word
    • it can be a lot of things, you have to watch and pick - Slava Nikitina
    • Try to bring the content from the template into a separate file - Slava Nikitina