【发布时间】:2019-05-26 16:51:28
【问题描述】:
在阅读了许多 SO 文章后,我认为我是正确的,但我不断收到错误消息。基本上,在我的 content.php 页面模板中,我想根据您是在存档页面还是单个帖子页面上显示不同的文章标签。所以我一直在做这样的事情:
<?php if ( is_archive() ) {
echo '<article id="post-' . the_ID() . '">';
} else {
echo '<article id="post-' . the_ID() . ' . "post_class() . '">';
}
?>
但是这里发生的不是它在页面上吐出 ID,所以生成的 HTML 看起来像这样:
1234<article id="post-">Content Goes Here</article>
什么时候应该……
<article id="post-1234">Content Goes Here</article>
那为什么显示不正确呢?
【问题讨论】:
-
我使用这样的代码更接近了: echo '
';所以类代码出现了,但又一次出现在归档标签之外。所以这是一团糟。