2013-09-27 47 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

相关问题