gpt4 book ai didi

php - 试图在 HTML 回显语句中获取 WordPress PHP

转载 作者:行者123 更新时间:2023-11-27 22:58:36 26 4
gpt4 key购买 nike

在阅读了很多 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>

那么为什么显示不正确?

最佳答案

the_ID()(以及许多其他 WP 函数)有一个变体 get_the_ID(),您会想在这里使用它。 the_ID() 在内部做自己的 echo; get_the_ID() 返回它。

关于php - 试图在 HTML 回显语句中获取 WordPress PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53965702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com