下面只是一个提供上下文的场景,以便您理解我试图完成的任务,但是请尽可能将您的答案与标题和css解决方案/功能联系起来。
我有一个我正在工作的播客网站。我在播客帖子页面上有“next”(下一集)和“prev”(上一集)按钮,用户可以按日期进入下一集播客,这些按钮只显示在播客帖子类别中。
(因此,只需在一个名为“播客”的类别中定期发布wordpress博客帖子)
我的问题是最近的播客帖子(例如,播客Ep#150)会显示“下一集”按钮。-由于Ep#150是最新的播客帖子,因此不应显示“下一步”按钮。现在,当你按下“Ep#1”时,它会把你带到“Ep#1”,这很有意义,但我不想让用户在我们的最新帖子上看到旧的剧集。
所以我只想“显示:无播客类别中最新帖子上的按钮。
谢谢你的帮助!
<span class="prev-ep-wrap">
<span class="prev-ep">
<?php next_post_link_plus( array( \'order_by\' => \'post_date\', \'loop\' => true, \'tooltip\' => \'Previous Episode\', \'in_same_cat\' => true, \'ex_cats\' => \'30, 11\', \'link\' => \'Previous Episode\' ) );?>
</span>
</span>
<span class="next-ep-wrap">
<span class="next-ep">
<?php previous_post_link_plus( array( \'order_by\' => \'post_date\', \'loop\' => true, \'tooltip\' => \'Next Episode\', \'in_same_cat\' => true, \'ex_cats\' => \'30, 11\', \'link\' => \'Next Episode\' ) );?>
</span>
</span>
SO网友:kero
I highly suggest using L.Milo\'s answer, since this will actually solve the problem and adding custom CSS will only masquerade it.
To add custom CSS to the latest post of a category, the following should work. It does the following
- Get the id of the latest post of that category using
wp_get_recent_posts()
- Check if currently a single post is displayed and if so, check if it has the id of the latest post (ie., it is the latest post)
- If so, enqueue another stylesheet.
<?php
function wpse_enqueue_on_latest_post() {
$args = array(
\'numberposts\' => 1,
\'category\' => 12,// id of the category
);
list($latest) = wp_get_recent_posts($args);
if (is_single( $latest[\'ID\'] )) {
wp_enqueue_style( ... );
}
}
add_action(\'init\', \'wpse_enqueue_on_latest_post\');
Alternatively, you could add a custom body class and use the same stylesheet, where you differentiate exactly via that class
<?php
function wpse_add_latest_post_body_class($classes) {
$args = array(
\'numberposts\' => 1,
\'category\' => 12,// id of the category
);
list($latest) = wp_get_recent_posts($args);
if (is_single( $latest[\'ID\'] )) {
$classes[] = \'latest-of-category-xxx\';
}
return $classes;
}
add_filter(\'body_class\', \'wpse_add_latest_post_body_class\');