Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1130349
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI'm trying to find a way how to have a simple conditional whereby I can echo something depending on whether the post date is in the first half or last half of the post date year.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI'm trying to find a way how to have a simple conditional whereby I can echo something depending on whether the post date is in the first half or last half of the post date year.
Share Improve this question asked Dec 7, 2018 at 5:43 PetePete 1,0582 gold badges14 silver badges40 bronze badges 2- And what have you tried so far? See wordpress.stackexchange/help/how-to-ask. You're basically looking at extracting the MM out of YYYYMMDD, convert to int, and check if greater than 6. – anmari Commented Dec 7, 2018 at 7:03
- I don't know where to start – Pete Commented Dec 7, 2018 at 12:37
2 Answers
Reset to default 2Are you thinking of something like this?
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
if ( absint( get_the_date( 'n' ) ) <= 6 ) {
// First half of year
...
} else {
// Second half of year
...
}
}
}
I found this elsewhere and it worked for me...
if( (int)get_the_time( 'm' ) <= 6 ) {
echo 'Some time between January and June.';
} else {
echo 'Some time between July and December.';
}
Closed. This question is off-topic. It is not currently accepting answers.
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI'm trying to find a way how to have a simple conditional whereby I can echo something depending on whether the post date is in the first half or last half of the post date year.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI'm trying to find a way how to have a simple conditional whereby I can echo something depending on whether the post date is in the first half or last half of the post date year.
Share Improve this question asked Dec 7, 2018 at 5:43 PetePete 1,0582 gold badges14 silver badges40 bronze badges 2- And what have you tried so far? See wordpress.stackexchange/help/how-to-ask. You're basically looking at extracting the MM out of YYYYMMDD, convert to int, and check if greater than 6. – anmari Commented Dec 7, 2018 at 7:03
- I don't know where to start – Pete Commented Dec 7, 2018 at 12:37
2 Answers
Reset to default 2Are you thinking of something like this?
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
if ( absint( get_the_date( 'n' ) ) <= 6 ) {
// First half of year
...
} else {
// Second half of year
...
}
}
}
I found this elsewhere and it worked for me...
if( (int)get_the_time( 'm' ) <= 6 ) {
echo 'Some time between January and June.';
} else {
echo 'Some time between July and December.';
}
本文标签: Conditional IF post creation date is in the first half OR last half of the year
版权声明:本文标题:Conditional: IF post creation date is in the first half OR last half of the year 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749119092a2318693.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论