国产精在线-国产精欧美一区二区三区-国产精视频-国产精品 日韩-一级黄色片在线看-一级黄色片在线播放

CorePress使用插件的方式添加文章和頁面模板

網上的方法都比較麻煩,整理了一下代碼,只需要替換頁面名稱和頁面路徑即可

define('CP_PLUGIN_DIR', plugin_dir_path(__FILE__));
$cp_page_templates = array(
    array("slug" => "page-corepress.php",
        "name" => "CorePress-Pro主題頁面",
        "path" => CP_PLUGIN_DIR . "/page-corepress.php",
    ),
);
add_filter('page_template', 'cp_page_template');
add_filter('single_template', 'cp_page_template');
function cp_page_template($page_template)
{
    global $cp_page_templates;
    $slug = get_page_template_slug();
    foreach ($cp_page_templates as $item) {
        if ($slug == $item['slug']) {
            $page_template = $item['path'];
        }
        return $page_template;
    }
}
add_filter( 'theme_page_templates', 'cp_page_add_template_to_select', 10, 4 );
add_filter( 'theme_post_templates', 'cp_page_add_template_to_select', 10, 4 );

function cp_page_add_template_to_select( $post_templates, $wp_theme, $post, $post_type ) {
    global $cp_page_templates;
    foreach ($cp_page_templates as $item) {
        $post_templates[$item['slug']] = $item['name'];
    }
    return $post_templates;
}

其中,只需要修改$cp_page_templates變量里面的參數即可,slug為文件名稱,name為模板名稱,path為文件路徑。多個模板,多添加幾個array即可。

另外用的時候,建議也改一改常量CP_PLUGIN_DIR,改成唯一的名字。

 

THE END
主站蜘蛛池模板: 国产一级特黄一级毛片 | 欧美成人在线观看 | 三级网站免费看 | 久久99热精品免费观看欧美 | 欧美另类色 | 欧美日韩一二区 | 最新理论三级中文在线观看 | 国产成人精品午夜二三区 | 成人69视频在线观看免费 | 91影视做在线观看免费 | 久久久久久青草大香综合精品 | 亚洲精品久久片久久 | 精品国产免费第一区二区三区日韩 | 美女一级视频 | 日本暖暖在线视频 | 欧美变态一级毛片 | 天堂8中文在线 | 99j久久精品久久久久久 | 日韩一区二区三区免费视频 | 九色国产在线 | 2019偷偷狠狠的日日 | 精品久久久久久中文字幕 | 亚洲超大尺度激情啪啪人体 | 欧美一级特黄aaaaaa在线看首页 | 精品国产成a人在线观看 | 色老久久精品偷偷鲁一区 | 免费看美女午夜大片 | 国产在线视频h | 91成年人视频| 免费观看成人久久网免费观看 | 真人一级一级特黄高清毛片 | 99精品一区二区免费视频 | 欧美一级毛片免费看高清 | 人成午夜 | 久久久毛片免费全部播放 | 国产视频综合 | 国产精品黄页在线播放免费 | 日本久久久久久久 | 国产精品久久久久久久久福利 | 国产亚洲精品一区999 | 成人在线一区二区 |