【发布时间】:2016-03-11 17:42:36
【问题描述】:
我总是收到相同的帖子。我不明白为什么我总是收到相同的帖子(第一个)而不是所有帖子。有人吗?
我怎样才能得到第二个或第三个等?
function my_lateral_fluid() {
$data = array();
$args = array(
"post_type" => "portfolio",
"posts_per_page" => -1
);
$portfolio_query = new WP_Query($args);
while($portfolio_query -> have_posts() ){
$portfolio_query -> the_post();
$data = '
<div id="all-content" class="container abs-position">
<div id="primary" class="content-area-ajax text-center">
<main id="main" class="site-main" role="main">
<article id="post-'. get_the_ID().'"'. post_class().'>
<h1 class="entry-title">'.get_the_title().'</h1>
<div class="entry-content">'.get_the_content().'</div>
</article>
</main>
</div>
</div>
';
}
wp_reset_postdata();
echo '<div id="postdata">'.$data.'</div>';
wp_die();
}
这里是lateral-fluid.js
var origHeight= 0;
jQuery(function($){
jQuery('.more-info').click(function() {
origHeight = jQuery('#show').height();
//var postid = $(this).attr('data-postid');
var page = jQuery(this).attr('data-href');
jQuery.ajax({
url: ajaxFluid.ajaxurl,
type: 'get',
page: page,
data: {
action: 'lateral_fluid'
},
success: function( data ) {
console.log(data);
var $response = $(data);
var postdata = $response.filter('#postdata').html();
//ajax load data
jQuery('#ajax-inserted1').html(postdata);
//animate portfolio grid to left
jQuery('#remove').removeClass('to-screen').addClass('to-left');
},
complete: function(){
//animate post to screen from right to left
jQuery('.entry-content a img, .entry-content img').load(function () {
jQuery('#ajax-inserted1, .controlls').removeClass('to-right').addClass('to-screen');
//HEIGHT CONTENT CALCULATION
var newHeight = jQuery('#ajax-inserted1 #primary').height()+100;
var el = jQuery('.show-container');
el.css({'height': newHeight + 'px'});
//STELLAR REFRESH
setTimeout(stellarRefresh, 500);
function stellarRefresh() {
jQuery.stellar('refresh');
}
});
}
});
});
jQuery('#close-portfolio').click(function() {
jQuery('#ajax-inserted1').removeClass('to-screen').addClass('to-right');
jQuery('#remove').removeClass('to-left').addClass('to-screen');
jQuery('.controlls').removeClass('to-screen').addClass('to-right');
//ORIGINAL HEIGHT
jQuery('.show-container').css({'height': origHeight + 'px'});
setTimeout(ajaxEmpty, 500);
function ajaxEmpty() {
jQuery('#ajax-inserted1').empty();
}
});
});
【问题讨论】:
-
在代码中看起来没有问题......你在哪里调用你的函数 my_lateral_fluid()?你能把代码吗?
-
@PHPWeblineindia 代码有问题 ;-)
-
您将
$data定义为一个数组,然后用一个字符串填充它。那么您希望$data是什么?数组还是字符串?如果它是一个字符串,则将其定义为$data = '';,然后在您的 while 中执行:$data . = '.. html here ..';。 -
这看起来像一个你想在 ajax 上调用的函数。如果是这样,请发布更多详细信息,您的原始 php 文件,您的 ajax 调用等...
-
@dingo_d 我用 javascript 代码更新了这个问题。抱歉耽误我睡觉了。
标签: php ajax wordpress custom-post-type