Php 获取循环中不同帖子的帖子元
我有一个名为“视频”的自定义帖子类型,在该自定义帖子类型中,我有一个元框,用户可以在其中粘贴vimeo链接。我试图查询视频自定义帖子类型的元数据,但是下面的代码为每个帖子返回相同的元数据(vimeo链接),尽管它们在仪表板中不同。我希望每个帖子在循环中都有自己的vimeo链接。谢谢你的帮助!如果我需要更清楚一些,请告诉我Php 获取循环中不同帖子的帖子元,php,wordpress,vimeo,Php,Wordpress,Vimeo,我有一个名为“视频”的自定义帖子类型,在该自定义帖子类型中,我有一个元框,用户可以在其中粘贴vimeo链接。我试图查询视频自定义帖子类型的元数据,但是下面的代码为每个帖子返回相同的元数据(vimeo链接),尽管它们在仪表板中不同。我希望每个帖子在循环中都有自己的vimeo链接。谢谢你的帮助!如果我需要更清楚一些,请告诉我 $args = array( 'post_type' => 'video', 'posts_per_page' => 10,); $the_query = new
$args = array( 'post_type' => 'video', 'posts_per_page' => 10,);
$the_query = new WP_Query( $args );
echo '<section id="our-work">';
echo '<div class="row-fluid">';
$i = 1;
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
global $post;
$vimeo = get_post_meta( $post->ID, '_cmb_test_embed', true );
$counter += 1;
if($counter == 4 || $counter == 5 || $counter == 9 || $counter == 10) :
echo '<div class="span6">';
the_post_thumbnail();
echo '</div>';
else:
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail_name');
$vimeo_id = (int) substr(parse_url($vimeo, PHP_URL_PATH), 1); ?>
<div class="span4">
<div class="myModalThumbnail"><img src="<?php echo $thumb[0]; ?>"/></div>
</div>
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<iframe src="//player.vimeo.com/video/<?php echo $vimeo_id; ?>?title=0&byline=0&portrait=0&color=cc6f1a" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
</div>
<?php endif;
// if multiple of 3 close div and open a new div
if($i == 3 || $i == 5 || $i == 8 || $i == 10) {echo '</div><div class="row-fluid">';}
$i++; endwhile; endif;
echo '</div>';
echo '</section>';
// Reset Post Data
wp_reset_postdata();
?>
$args=array('post_type'=>'video','posts_per_page'=>10,);
$thew_query=newwp_query($args);
回声';
回声';
$i=1;
if($the_query->have_posts()):while($the_query->have_posts()):$the_query->the_post();
全球$员额;
$vimeo=get_post_meta($post->ID,''cmb_test_embed',true);
$counter+=1;
如果($counter==4 | |$counter==5 | |$counter==9 | |$counter==10):
回声';
_post_缩略图();
回声';
其他:
$thumb=wp\u get\u attachment\u image\u src(get\u post\u thumbnail\u id(),'thumbnail\u name');
$vimeo_id=(int)substr(parse_url($vimeo,PHP_url_PATH),1);?>
"/>
×
更新-
我找出了问题的原因。这是模式的jQuery。模式显示每个帖子的第一个帖子链接。参见示例。单击“虚拟图像”,您将了解我的意思。如何动态分配选择器,使每个帖子图像显示其对应的vimeo链接?使用
检索当前帖子的数字ID。此标记必须在
编辑在循环开始时尝试初始化为空,如
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
$vimeo_id ="";
$vimeo="";
编辑
您已经分配了id=“myModal“
对于多个元素,但中的id属性在html标准中应该是唯一的,一旦分配,不要对其他元素使用相同的id。相反,您可以使用class属性。我在html和javascript中做了一些更改。请参阅如何动态管理帖子的模式弹出窗口
jQuery(document).ready(function($) {
$('.myModalThumbnail').click(function () {
var modalclass= $(this).attr('id');
$("."+modalclass).modal('show');
});
});
<div class="span4">
<div class="myModalThumbnail" id="post-<?php echo get_the_ID();?>"><img src="<?php echo $thumb[0]; ?>"/></div>
</div>
<div class="modal hide fade post-<?php echo get_the_ID();?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<iframe src="//player.vimeo.com/video/<?php echo $vimeo_id; ?>?title=0&byline=0&portrait=0&color=cc6f1a" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
</div>
jQuery(文档).ready(函数($){
$('.myModalThumbnail')。单击(函数(){
var modalclass=$(this.attr('id');
$(“+modalclass).modal('show');
});
});
使用
检索当前帖子的数字ID。此标签必须在
编辑在循环开始时尝试初始化为空,如
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
$vimeo_id ="";
$vimeo="";
编辑
您已经分配了id=“myModal”
对于多个元素,但中的id属性在html标准中应该是唯一的,一旦指定,不要对其他元素使用相同的id,相反,您可以使用class属性。我在html和javascript中做了一些更改。请参见如何动态管理帖子的模式弹出窗口
jQuery(document).ready(function($) {
$('.myModalThumbnail').click(function () {
var modalclass= $(this).attr('id');
$("."+modalclass).modal('show');
});
});
<div class="span4">
<div class="myModalThumbnail" id="post-<?php echo get_the_ID();?>"><img src="<?php echo $thumb[0]; ?>"/></div>
</div>
<div class="modal hide fade post-<?php echo get_the_ID();?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<iframe src="//player.vimeo.com/video/<?php echo $vimeo_id; ?>?title=0&byline=0&portrait=0&color=cc6f1a" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
</div>
jQuery(文档).ready(函数($){
$('.myModalThumbnail')。单击(函数(){
var modalclass=$(this.attr('id');
$(“+modalclass).modal('show');
});
});
看起来,$post
一点也不递增,你一直在做$post->ID
,一次又一次地得到相同的ID
。我认为你不需要带自定义查询的global$post
。看起来,$post
一点也不递增,你一直在做$post->ID
,然后得到更多相同的ID
一次又一次。我认为您不需要使用自定义查询的global$post
。我使用您的建议更新了脚本,但它仍然返回相同的vimeo id。我认为是我提取vimeo链接的方式导致了问题,因为如果我回显$vimeo,它将返回不同的值,就像它假设的那样。@这家伙看到了我更新的答案,还回显了该id()代码>在循环中查看id是否正在更改谢谢dianuj的帮助!我很感激。我解决了这个问题-请参阅上面的更新。这正是我想要的!再次感谢您的帮助。我使用您的建议更新了脚本,但它仍然返回相同的vimeo id。我认为是我提取vimeo链接的方式导致了问题,因为如果我回显$vimeo,它将返回不同的值,就像它假设的那样。@这个家伙看到了我更新的答案,并且回显获取了该id()代码>在循环中查看id是否正在更改谢谢dianuj的帮助!我很感激。我解决了这个问题-请参阅上面的更新。这正是我想要的!再次感谢你的帮助。