php - 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());
解决方案
没关系!我只记得我有一些 JavaScript 正在改变加载的 h2 类。
推荐阅读
- python - Python Seaborn ValueError:这些“样式”级别缺少破折号
- python - openCV Python中input()的等效函数
- simulator - 如何在 Connect IQ 设备模拟器中模拟活动信息 elapsedDistance?
- html - 我正在尝试使我的图像适合容器,但它们被放大了
- sql-server - AWS DMS 跳过 SQL Server 中的某些表列
- python - 不和谐的自我机器人表现得像无法阅读消息
- postgresql - Postgres 似乎陷入僵局
- amazon-web-services - netlify 如何做域代理?
- merge - EPPlus中合并单元格的自动调整行宽
- python - 如何准备和使用子目录名称作为 CNN 的标签?