2016-09-24 117 views
0

我目前正在智能mag主題中,在主頁newsticker中默認發佈所有最新消息。但是我想表明的newsticker.For,我安裝了插件添加新的崗位「元box'.And在寫了一個自定義元場獲取自定義字段值並顯示在前端wordpress

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; ?> 

任何幫助都非常感謝。

回答

0

您必須在比較的環路中添加條件rwmb_meta('radio')
Check documentation for more details about rwmb_meta

這可能是看起來像這樣:

<?php while($query->have_posts()): $query->the_post(); ?> 
    <?php if(rwmb_meta('radio') == 'Yes'): ?> 
     <li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> 
    <?php endif; ?> 
<?php endwhile; ?> 

的另一種方式,可能會更好,是通過添加您尋找鍵和meta值改變WP_Query。

<?php $query = new WP_Query(apply_filters('bunyad_ticker_query_args', array('meta_key' => 'radio', 'meta_value' => 'Yes','orderby' => 'date', 'order' => 'desc', 'posts_per_page' => 8))); ?> 
+0

我已經看過了documetation,但不明白在第二個文件中添加循環的位置。請幫助 –

+0

我被編輯了我的答案。我希望你能處理它:) –

+0

非常感謝,它工作 –

相關問題