首页 > 解决方案 > get_template_part 似乎正在删除 h2 上的一个类

问题描述

我正在开发一个自定义模板部分,其中包括一个带有“sectionmarker”和“bodycontent”类的h2,如下所示:

<h2 class="sectionmarker bodycontent">Title</h2>

当我在页面上调用 get_template_part() 时,我得到的输出是:

<h2 class="bodycontent">Title</h2>

出于某种原因,它似乎不喜欢“sectionmarker”。我什至切换了两个类的顺序,如下所示:

<h2 class="bodycontent sectionmarker">Title</h2>

我得到了相同的输出,只应用了 bodycontent 类。这里发生了什么?

完整模板内容:

<?php
$abstract=get_post_field('post_content',224);
  $news=get_posts(array(
    'post_type'=> 'news'
  ));

  $newsdata=array();
  foreach ($news as $n) {
    $item=new stdClass();
    $item->title=get_the_title($n->ID);
    $item->date=get_the_date("",$n->ID);
    $item->content=get_field('more_info',$n->ID);
    array_push($newsdata,$item);
  }

  $newsdata_json=json_encode($newsdata);
?>
<script type="text/javascript">
  console.log(<?php echo $newsdata_json ?>);
</script>

<?php
  echo $abstract;
  if(count($newsdata)>0){
?>
  <h2 class="sectionmarker bodycontent" >News</h2>
    <?php foreach ($newsdata as $newsitem) { ?>
      <h4 class='datemarker bodycontent'><?php echo $newsitem->date ?></h4>
      <p class='newstext bodycontent'><?php echo $newsitem->title ?></p>

<?php } } ?>

这是我正在打的电话(在 home.php 中):

get_template_part('custom-home-template',null,array());

标签: phpwordpresswordpress-theming

解决方案


没关系!我只记得我有一些 JavaScript 正在改变加载的 h2 类。


推荐阅读