2013-09-27 40 views
0

我已經設置爲自定義後的類型和音樂,商業,促銷這篇文章類型中設置爲類視頻:顯示自定義職位類型的自定義字段信息

我有一個顯示自定義的元函數在wordpress後端的視頻文章類型頁面上打開框。用戶可以輸入YouTube視頻的ID或VIMO視頻的ID - wordpress然後在自定義帖子類型頁面上顯示ID的視頻。當用戶向視頻自定義帖子類型添加新帖子並將其分配給我指定的任何類別時,我希望wordpress能夠顯示不同的視頻。我目前的代碼沒有做我想做的事情,因爲它在每個帖子上都顯示相同的視頻,即使某些ID上沒有指定ID也是如此。例如,在音樂文章頁面上,我已經爲其分配了類別音樂,並在前端顯示了一個vimeo視頻ID,但之後顯示的是同一個視頻用於促銷和廣告,我不希望發生這種情況。我已經運行這個循環是(單videos.php):

<?php 

$args = array('post_type' => 'videos', 'posts_per_page' => 20, 'orderby' => 'date', 'order' => 'ASC'); 
        $loop = new WP_Query($args); 
        while ($loop->have_posts()) : $loop->the_post(); 
//$args = array('post_type' => 'videos', 'posts_per_page' => 20, 'orderby' => 'date', 'order' => 'ASC'); 
$ytubeID = get_post_meta($post->ID, '_youtubeID', true); 
$vimID = get_post_meta($post->ID, '_vimeoID', true); 
if ($ytubeID || $vimID){ 
if ($ytubeID){ 

echo '<iframe title="YouTube video player" class="youtube-player" type="text/html" src="http://www.youtube.com/embed/'.$ytubeID.'" allowfullscreen="true" frameborder="0" width="640" height="390">'; 

echo '</iframe>'; 
} elseif ($vimID){ 
echo '<br />'; 
echo '<iframe src="http://player.vimeo.com/video/'.$vimID.'" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; 
}//end if yutbeID or vimIDthe_excerpt(); //excerpt added for information 
} 

endwhile; 
        wp_reset_query(); 

?> 
+0

[是跨張貼在多個棧Exchange站點問題如果問題是針對每個網站的主題,是否允許?](http://meta.stackexchange.com/q/64068/185667) – brasofilo

+0

Im sorry @brasofilo我真的不知道。 –

+0

那麼,答案是否定的,不要在2個網站中多發帖子。 – brasofilo

回答

1

顯示視頻接通電流的職位範疇的基礎

<?php 

    $args = array('post_type' => 'videos', 'posts_per_page' => 20, 'orderby' => 'date', 'order' => 'ASC'); 

    $loop = new WP_Query($args); 
    while ($loop->have_posts()) : $loop->the_post(); 

     //$args = array('post_type' => 'videos', 'posts_per_page' => 20, 'orderby' => 'date', 'order' => 'ASC'); 
     $ytubeID = get_post_meta($post->ID, '_youtubeID', true); 
     $vimID = get_post_meta($post->ID, '_vimeoID', true); 

     $videos_categories = array();   // ARRAY CONTAINING ALL CATEGORY ID ASSIGNED TO THIS POST 
     $videos_cat_id = get_the_category(); // GET ALL CATEGORIES OBJECT ASIGNED TO CURRENT POST 

     foreach($videos_cat_id as $videos_catid){ 
      $videos_categories[] = $catid->cat_ID; 
     } 
     $videos_cat_to_check = get_cat_ID($videos_cat_name ) // EXAMPLE get_cat_ID('music' ) 



     if ($ytubeID || $vimID){ 
      if ($ytubeID && in_array($videos_cat_to_check,$videos_categories)){ // CHECK IF CURRENT POST HAS CATEGORY MUSIC 

       echo '<iframe title="YouTube video player" class="youtube-player" type="text/html" src="http://www.youtube.com/embed/'.$ytubeID.'" allowfullscreen="true" frameborder="0" width="640" height="390">'; 

       echo '</iframe>'; 
       } elseif ($vimID){ 
       echo '<br />'; 
       echo '<iframe src="http://player.vimeo.com/video/'.$vimID.'" width="640" height="390" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; 
       }//end if yutbeID or vimIDthe_excerpt(); //excerpt added for information 
     } 

    endwhile; 
    wp_reset_query(); 

    ?> 
+0

感謝您的建議@wordpresser,但您的代碼正在拋出服務器錯誤。我認爲這可能是一個語法問題,但我不能解決它:( –

+0

我發現在這行後需要一個分號的語法問題:'$ videos_cat_to_check = get_cat_ID($ videos_cat_name)'我也發現我的循環問題我發現使用while循環會在正確的分類頁面上顯示每個視頻,所以現在顯示與視頻類別相關的視頻,而不是所有的視頻被轉出(像他們早些時候)while循環造成這種情況。刪除它並回顯每個視頻下的類別,以確保它顯示的是該類別的正確視頻。 –

+0

故事的寓意是你有你的代碼工作,ñ多數民衆贊成在! – codepixlabs

相關問題