我试图通过自定义的php模板从模板页面中删除页眉和页脚,但希望保留主题的原始样式。 我已经成功删除了页脚,但是我被卡在标题上,我做了一些调整我松开了样式,或者我得到了一个空白的屏幕。
<?php
/**
* Template Name: No Header or Footer
* This template will only display the content you entered in the page editor
*/
?>
<?php
get_header();
if (have_posts()) : the_post();
?>
<div class="mainrows">
<div class="large-12 columns">
<div class="leftside fullwidth">
<?php
if(of_get_option('headertype')!='header3'){ $goni = "0";} else { $goni = "0";}
$bgattachment = get_post_meta(get_the_ID(), '_az_header_bg', true);
$bgtext = get_post_meta(get_the_ID(), 'titleofimg', true);
if(($bgattachment)&&(of_get_option('headertype')=='header3')){ $klaz = ";margin-top:-70px!important"; } else { $klaz = '';}
if($bgattachment){
echo '<div class="wpb_wrapper" style="margin-top:'.$goni.'px'.$klaz.'"><div class="wpb_text_column wpb_content_element ">';if($bgtext!=""){ echo '<div class="txtwr"><h1>'.$bgtext.'</h1>';} echo '<img src="'.$bgattachment.'" style="margin:0 auto!important;float:none;display:block;text-align:center;width:100%" class="phoneup" alt="" />';if($bgtext!=""){ echo '</div>';} echo '</div></div>';
}
echo '<div class="wrap1170 inwrap">';
if (getmb("hidetitle") != 'yes') {
$bgattachment = get_post_meta(get_the_ID(), '_az_header_bg', true);
if(!$bgattachment){
?>
<h1 style="margin-bottom:15px;margin-top:40px"><?php the_title(); ?></h1>
<?php
}
} the_content();?>
</div>
</div>
</div>
<?php
endif;
?>
答案 0 :(得分:2)
get_header()
不仅仅是添加布局的顶部部分。因此,您要在此模板中执行的操作是将变量设置为true
并在header.php
和footer.php
内使用它(如果您希望页脚和标题是独立的,请添加两个变量) :
<?php
$hide_header = true;
get_header();
...
在header.php
内,您可以将想要不显示的HTML标记包装在ifs:
if (!$hide_header) {
// existing code outputting the top part of the layout
} else {
// here you might put a simplified version of the top part
// opening any tags that are closed later in the layout
// also, make sure you call wp_head(). Your theme and plugins
// depend on it to load .js and .css files
wp_head();
}
在执行此操作时,您还应确保不要破坏布局。必须在主模板或header.php
中关闭footer.php
中打开的所有代码。
原则上,您不想删除对get_header()
和get_footer()
的调用,因为它们是WordPress页面生命周期中的重要步骤,许多插件依赖于调用的操作那些模板。您只想阻止这些模板输出一些HTML标记。
注意:根据主题,禁用布局的顶部和底部可能会很困难,尤其是如果它们具有特殊的定位规则。有时,最简单的方法是向<body>
添加一个类,并在要隐藏的元素上使用display:none
。
另请注意,大多数不错的主题已经提供了在选项页面内隐藏页眉和/或页脚的选项。检查您的主题中是否已经存在这一点,您所要做的就是(联系)检查主题选项中的勾号。其他主题提供了不基于逐页设置显示标题的选项,通常显示在页面meta_boxes中。
答案 1 :(得分:0)
所有css和js都可以在header.php中找到
如果删除 get_header(),将不再加载header.php,也不会加载css,js也将被加载。
您可以在上面创建的自定义模板中指定css和js的路径,然后移除 get_header()
它会起作用。