根据星期几自动显示自定义Wordpress分类标签


Display a custom Wordpress taxonomy tag automatically based on the day of the week?

我有一个客户端,希望在Wordpress中按星期几自动显示自定义分类法标记。基本上,我们将有一个名为"products"的自定义帖子类型和一个名为"day"的分类法。在"day"中,我们将有七个标签,一个代表一周中的每一天,任何标有一周中特定一天的内容将在当天显示在主页上。

因此,例如,如果产品A, B &C在分类法"day"中都被分配了一个"Wednesday"的标签,今天是星期三,然后这些项目将显示在主页上。如产品D、E;F被分配到周四,他们会在周四出现,以此类推。

说了这么多,我需要帮助的部分是编写一个可以检测星期几的循环,然后查询适当的分类法标记。有人知道该怎么做吗?我真的找不到任何关于这方面的参考资料,我的PHP技能充其量是初级的。: -/

这是我目前使用的循环,用于根据自定义帖子类型,分类&条件:

<?php query_posts('post_type=products&taxonomy=day&term=wednesday&posts_per_page=10'); ?>
<?php if(have_posts()) : while (have_posts() ) : the_post(); ?>
<div class="archivecustompost">
<div class="archivecustomleftblock">
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( array(150,150) ); ?></a>
</div>
<div class="archivecustomrightblock">
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p class="button"><a href="<?php the_permalink() ?>" rel="bookmark">Learn More</a></p>
</div>
</div>
<?php endwhile; endif; ?>

您应该尝试这样做,

使用WP_Query
$day = date("l"); // Gives the todays day.
$wpq = array (post_type =>'product','taxonomy'=>'day','term'=>$day);
$query = new WP_Query ($wpq);
使用<<p> strong> query_post :
$day = date("l");
$args = 'post_type=products&taxonomy=day&term='.$day.'&posts_per_page=10';
query_posts($args);