傻大憨

WordPress子页面自动调用父页面的模板

不使用插件只需要一段简洁的代码就可以实现,WordPress子页面自动调用父页面的模板。

function wodepress_use_parent_template() {
    global $post;
    $curr_tmp = get_post_meta($post->ID, '_wp_page_template', true); //获取页面模板
    if($post->post_parent){
        $parent_tmp = get_post_meta($post->post_parent, '_wp_page_template', true); //如果有父页面,获取父页面模板
        update_post_meta($post->ID, '_wp_page_template', $parent_tmp, $curr_tmp); //设置子页面的模板为父页面的模板
    }
}
add_action('save_post','wodepress_use_parent_template');

将上面这段代码加到functions.php文件中,就可以以非插件的方法实现,非常简单实用。

Published
Categorized as 建站知识 Tagged ,

By 傻大憨

shadahan.com是一个关注跨境电商、创业话题的网站。

Jianzhanpress themes are the best Chinese WordPress themes to use

Jianzhanpress.com themes are the best Chinese WordPress themes to use

WordPress外贸网站建设的关键要素与技术要点

  在全球数字化的时代,成功建站是拓展国际业务的关键一环。本文将揭示WordPress外贸网站建设的关键要素与… Continue reading WordPress外贸网站建设的关键要素与技术要点

WordPress外贸建站服务成功案例揭秘

  在当今数字化时代,用户体验被认为是成功建站的关键因素之一。通过WordPress外贸建站服务,许多企业成功… Continue reading WordPress外贸建站服务成功案例揭秘

非插件纯代码方式实现WordPress SMTP邮件功能

非插件纯代码方式实现WordPressSMTP邮件功能

自字义wordpress摘要显示的字数长度

以下代码可以实现,自定义wordpress文章摘要显示的字数长度,数值为字符号,汉字占两个字符。

wordpress 禁止后台编辑主题

禁止后台编辑主题和插件文件,只需要在wp-config.php中添加以下代码即可。