编码新手。预先感谢您的帮助:)
我已经获得了点击帖子后显示的日期(一个帖子在一个页面上),但它不会显示在包含所有帖子的主页上。
我如何将它应用到主页/首页/主页上的帖子? 我如何在 CSS 中修改它? (例如,更改颜色或字体)
这是在 functions.php 中:
function add_after_post_content($content) {
if(!is_feed() && !is_front_page() && !is_home() && is_singular() && is_main_query()) {
$content .= '<p> Posted '.date('F j, Y').' '.'</p>';
}
return $content;
}
add_filter('the_content', 'add_after_post_content');
最佳答案
对于 functions.php
中的 PHP ,尝试更改为:
function add_after_post_content($content) {
if(!is_feed() && is_singular() && is_main_query()) {
$content .= '<p> Posted '.date('F j, Y').' '.'</p>';
}
return $content;
}
add_filter('the_content', 'add_after_post_content');
基本上,该函数的第二行使用 !is_front_page() && !is_home()
说“如果不是主页也不是首页,则执行此代码”,!is_home
作为 PHP/Wordpress 检查是否存在错误的方式。
对于样式,您可以将类添加到 <p>
在您的代码中添加标签,如下所示:
$content .= '<p class="my-date-style"> Posted '.date('F j, Y').' '.'</p>';
然后将其添加到您的 CSS 文件中:
.my-date-style {
color: blue;
}
在没有看到其余代码的情况下,很难做出肯定的判断,但这应该能让您朝着正确的方向前进。
关于php - 如何在主页上的帖子下方显示日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38511402/