【问题标题】:How remove a header and footer with affecting the styling in wordpress [closed]如何在影响wordpress样式的情况下删除页眉和页脚[关闭]
【发布时间】:2018-02-19 07:27:48
【问题描述】:

我试图通过自定义 php 模板从我的 wordpress 模板页面中删除页眉和页脚,但希望保留主题的原始样式。 我已成功删除页脚,但卡在页眉上,我所做的所有调整都失去了样式或出现空白屏幕。

<?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;
?>

【问题讨论】:

  • 确保你保留&lt;?php wp_head(); ?&gt; 这就是包含样式的方式
  • 对于它的价值,我认为这个问题已经因为错误的原因而被关闭。无论这是一个好问题、经过充分研究还是对未来的用户有帮助,都有待商榷,但对于任何了解 WordPress 中高级水平的人来说,这一点都非常清楚。为了认为它不清楚,人们必须不熟悉 WP 生态系统和页面生命周期,并且在我看来,在这种情况下,人们应该避免投票结束这个问题。因此,我提名重新开放的问题。

标签: php css wordpress templates


【解决方案1】:

get_header() 不仅仅是添加布局的顶部。所以你想要在这个模板中做的是将一个变量设置为true 并在header.phpfooter.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 标记。


注意:根据主题,禁用布局的顶部和底部部分可能会很困难,尤其是在它们具有特殊定位规则的情况下。有时,最简单的方法是向&lt;body&gt; 添加一个类,然后在要隐藏的元素上使用display:none

另请注意,大多数体面的主题已经在选项页面内提供了隐藏页眉和/或页脚的选项。检查这是否不存在于您的主题中,您所要做的就是(取消)选中主题选项中的勾号。其他主题提供了基于逐页设置不显示标题的选项,通常显示在页面 meta_boxes 中。

【讨论】:

    【解决方案2】:

    所有的css和js都在header.php中

    如果你去掉get_header(),header.php就不会被加载,css、js也会被加载。

    您可以在上面创建的自定义模板中提供 css 和 js 的路径,然后您可以删除 get_header()

    它会起作用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-11
      • 1970-01-01
      • 2021-01-29
      • 1970-01-01
      • 2013-06-29
      • 2023-03-11
      • 2015-12-06
      • 1970-01-01
      相关资源
      最近更新 更多