[英]How to display the date underneath posts on home page?
new to coding. 编码新手。 Thanks in advance for your help :) 在此先感谢您的帮助 :)
I've gotten the date to display on posts after they've been clicked (one post on a single page) but it won't show up on the main page with all the posts. 单击它们后,我已经知道要显示它们的日期(在一个页面上显示一个帖子),但是它不会显示在包含所有帖子的主页上。
How do I apply it to posts on the main/front/home page? 如何将其应用于主页/首页/首页上的帖子? How do I modify it in CSS? 如何在CSS中修改它? (change color or font, for instance) (例如,更改颜色或字体)
This is in the functions.php: 这是在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');
For the PHP in functions.php
, try changing to this: 对于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');
Basically, the second line of that function uses !is_front_page() && !is_home()
to say "if NOT the home page and NOT the front page then execute this code", !is_home
being the way PHP/Wordpress checks if something is NOT true. 基本上,该函数的第二行使用!is_front_page() && !is_home()
表示“如果不是主页,而不是首页,则执行此代码”, !is_home
是PHP / Wordpress检查是否存在某些!is_home
的方式真正。
For the styling, you can add a class to the <p>
tag in your code, like this: 对于样式,可以在代码中的<p>
标记中添加一个类,如下所示:
$content .= '<p class="my-date-style"> Posted '.date('F j, Y').' '.'</p>';
Then add this to your CSS file: 然后将其添加到您的CSS文件中:
.my-date-style {
color: blue;
}
Without seeing the rest of the code it's difficult to say for sure, but this should get you headed in the right direction. 没有看到其余的代码,很难确定,但这应该可以使您朝正确的方向前进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.