我目前正在使用智能杂志主题,在主页newsticker 中默认发布所有最新消息。但我只想在 newsticker 中显示选定的帖子。为此我安装了插件“元框”。并编写了一个自定义元字段
add_filter( 'rwmb_meta_boxes', 'breaking_news_radio_demo' );
function breaking_news_radio_demo( $meta_boxes )
{
$prefix = 'rw_';
$meta_boxes[] = array(
'title' => __( 'Breaking news', '$prefix' ),
'fields' => array(
array(
'name' => __( 'Show', 'rw' ),
'id' => 'radio',
'pages' => array('post-new'),
'type' => 'radio',
// Array of 'value' => 'Label' pairs for radio options.
// Note: the 'value' is stored in meta field, not the 'Label'
'options' => array(
'YES' => __( 'Yes', '$prefix' ),
'NO' => __( 'No', '$prefix' ),
),
),
)
);
return $meta_boxes;
}
元框在“添加新帖子”中显示良好。但是使用单选按钮我想控制哪些帖子显示在新闻收报器中。主题中的新闻标签使用以下代码显示
<?php if (!Bunyad::options()->disable_topbar_ticker): ?>
<div class="trending-ticker">
<span class="heading"><?php echo Bunyad::options()->topbar_ticker_text; // filtered html allowed for admins ?></span>
<ul>
<?php $query = new WP_Query(apply_filters('bunyad_ticker_query_args', array('orderby' => 'date', 'order' => 'desc', 'posts_per_page' => 8))); ?>
<?php while($query->have_posts()): $query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</ul>
</div>
<?php endif; ?>
非常感谢任何帮助。