首页 > 解决方案 > 我的页面使用的是我的 Index.php 而不是我的 page.php

问题描述

所以我正在制作一个自定义主题,我设置了主题在 wordpress 上创建了我的页面然后创建了我的 Pages VS 代码我将为此使用一个页面的示例:

我用 slug 创建了人才页面:人才

还有一个page-talent.php:

<?php
get_header();
?>
<div class="talent-arc container">
<?php echo do_shortcode('[visual_portfolio id="8"]'); ?>
</div>
<?php get_footer();?>

但是它使用我的Index.php而不是人才页面,我以前从来没有遇到过这个,通常它只是创建一个页面创建page-pagenamehere.php文件并编辑掉

我的永久链接设置为帖子名称:

我的函数 PHP:

<?php 

add_theme_support( 'menus' );
add_theme_support( 'post-thumbnails' );

function wpt_excerpt_length( $length ) {
    return 70;
}
add_filter( 'excerpt_length', 'wpt_excerpt_length', 999 );

function register_theme_menus() {

    register_nav_menus(
        array(
            'primary-menu' => __( 'Primary_menu' ),
            'footer-menu' => __( 'Footer_menu' ),
            'extra-menu' => __( 'Extra_menu' )
        )
    );

}
add_action( 'init', 'register_theme_menus' );


function wpb_image_editor_default_to_gd( $editors ) {
    $gd_editor = 'WP_Image_Editor_GD';
    $editors = array_diff( $editors, array( $gd_editor ) );
    array_unshift( $editors, $gd_editor );
    return $editors;
}
add_filter( 'wp_image_editors', 'wpb_image_editor_default_to_gd' );

function wpt_theme_styles() {
    wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/css/bootstrap.css' );
    wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/css/jquery-ui.min.css' );
    wp_enqueue_style( 'material_css', 'https://fonts.googleapis.com/icon?family=Material+Icons' );
}
add_action( 'wp_enqueue_scripts', 'wpt_theme_styles' );

function theme_js() {
            global $wp_scripts;
        wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/js/bootstrap.js', array('jquery'), '', false );
        wp_enqueue_script( 'jquery_ui_js', get_template_directory_uri() . '/js/jquery-ui.min.js', array('jquery'), '', false );
        wp_enqueue_script('custom_js', get_template_directory_uri(). '/js/script.js', array('jquery'), '', true);

    }

    add_action('wp_enqueue_scripts','theme_js');

    
function new_excerpt_more( $excerpt ) {
    return $excerpt. '... <a class="more-link" href="'. get_permalink( get_the_ID() ) . '">' . __('READ MORE') . ' </a>';
}
add_filter( 'get_the_excerpt', 'new_excerpt_more' );

function mytheme_setup() {
    add_theme_support('custom-logo');
}

add_action('after_setup_theme', 'mytheme_setup');



?>

CSS 模板

/*
Theme Name:  KellyJeanCasting Theme
Author: 
Author URI:
Description: Theme for kelly
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags:
Text Domain: VSS
*/

更新:将我的所有文件从例如 Talent 重命名为 -> Talent-main 并调整 slug 使其工作,我如何删除该行为

标签: wordpress

解决方案


确认您的页面 slug 是Talent,并且 page- talent.php位于主题文件夹的根目录中。

您也可以尝试使用页面 ID 进行测试,即:如果人才页面为 #6,则重命名 page-6.php

要使其成为全局模板,请将模板名称注释添加到 page-talent.php 的顶部,然后在编辑页面时手动选择该模板。

<?php
/**
* Template Name: Talent Page
*/

https://developer.wordpress.org/themes/template-files-section/page-template-files/


推荐阅读