使用无限滚动我尝试一次加载3个帖子,但只填写有特定字段(视频)的帖子。
例如,我最近的2个帖子填写了字段(视频),3d帖子没有,第4个帖子有。 我想要帖子1,2和& 4加载的原因使得3.然后无限滚动应该加载包括视频等的接下来的3个帖子
无限滚动有效,分页查询有效,但是:因为帖子3没有填写视频字段,无限滚动只加载帖子1& 2并没有添加帖子4来完成我想要的3个帖子......
我的代码:
<div id="interviews">
<?php $temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('paged='.$paged.'&cat=5&showposts=3');
while ($wp_query->have_posts()) : $wp_query->the_post();
echo ('<ul id="infinite">');
if (get('video_video', 1, TRUE)) {
echo ('<li class="video">');
$home = array("h" => 290, "w" => 380, "zc" => 1, "q" =>100);
//echo get('video_video');
echo ('With: ');
echo get('participant_first_name');
echo (' ');
echo get('participant_last_name');
echo ('</li>');
}else{ $video_video=false;
echo ('');
} ?>
<?php endwhile;?>
</ul>
<?php if ($wp_query->max_num_pages > 1) : ?>
<nav id="nav-below">
<div class="nav-previous"><?php next_posts_link( __( '← More', 'intowntheme' ) ); ?></div>
</nav>
<?php endif; ?>
</div><!--End interviews-->
Jquery脚本:
jQuery('#interviews').infinitescroll({
navSelector : "#nav-below", // selector for the paged navigation (it will be hidden)
nextSelector : "#nav-below .nav-previous a", // selector for the NEXT link (to page 2)
itemSelector : "li.video", // selector for all items you'll retrieve
extraScrollPx: 50,
loading : {
msgText: "<em>Loading the next year of Grantees...</em>",
finishedMsg: "<em>You've reached the end of the Grantees.</em>"
}
});
答案 0 :(得分:0)
之前我没见过get
功能。你知道它从哪个表中提取数据吗?如果是wp_postmeta
,您可以在WP_Query
中使用custom field parameters来仅从数据库中检索您感兴趣的记录。
类似的东西:
$wp_query = new WP_Query();
$wp_query->query('paged='.$paged.'&cat=5&showposts=3&meta_key=video_video&meta_value=1');
应该这样做。
答案 1 :(得分:0)
<div id="interviews">
<?php echo ('<ul id="infinite">'); ?>
<?php
$wp_query = new WP_Query();
$wp_query->query('paged='.$paged.'&cat=5&showposts=3&meta_key=video_video&orderby=meta_value&order=ASC' . $post->ID);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php if ( get_post_meta($post->ID, 'video_video', true) ) : ?>
<li class="video"><?php $home = array("h" => 290, "w" => 380, "zc" => 1, "q" =>100);
//echo get('video_video');
echo ('With: ');
echo get('participant_first_name');
echo (' ');
echo get('participant_last_name');
echo ('</li>');?>
<?php endif;?>
<?php endwhile;?>
<?php if (get_post_meta($post->ID, 'video_video', true) ) { ?>
<?php if ($wp_query->max_num_pages > 1) : ?>
<nav id="nav-below" >
<div id="next"><?php next_posts_link( __( 'Scroll down for more', 'intowntheme' ) ); ?></div>
</nav>
<?php endif; //end nav ?>
<?php } else { ?>
<p>There are no interviews at the moment </p>
<?php } ?>
</ul>
</div><!--End interviews-->