Php modx getResources-抵销/限额问题?
我已经设置好了,这样一个主博客页面会显示最初的3篇文章,当完全加载时会显示标签Php modx getResources-抵销/限额问题?,php,modx,Php,Modx,我已经设置好了,这样一个主博客页面会显示最初的3篇文章,当完全加载时会显示标签 [[!getResourcesTag? &element=`getResources` &elementClass=`modSnippet` &tpl=`blog-item` &tplFirst=`blog-item-feature
[[!getResourcesTag?
&element=`getResources`
&elementClass=`modSnippet`
&tpl=`blog-item`
&tplFirst=`blog-item-featured`
&limit=`3`
&hideContainers=`1`
&parents=`5`
&tagKey=`blog-tags`
&includeTVs=`1`
&tvPrefix=``
]]
显示的最初3篇文章在主登录页(最近的第一篇)上按日期顺序排序,例如第1条、第2条和第3条
点击显示的3篇文章下方的“更多文章”按钮,无限滚动分页(已设置)开始
<button class="load-more" data-parent="5" data-current-page="1">More Posts</button>
我一直在玩弄参数&试图修改处理offset
的代码,但似乎无法理解
一些帮助会很好。添加了更新的代码 不久前,我做了类似的事情,几乎完全是事实[一定是谷歌搜索到的] 我的初始getResources调用中唯一的区别是我使用了0的偏移量
<div id="posts">
<!-- get first few articles -->
[[!getResources?
&parents=`10,22`
&depth=`999`
&limit=`6`
&offset=`0`
&includeTVs=`1`
&processTVs=`1`
&includeContent=`1`
&tpl=`infiniteHomePageTpl`
&sortby=`publishedon`
&showHidden=`1`
&hideContainers=`1`
]]
</div>
<button id="scroller" class="btn btn-primary load-more" data-parents="10,22" data-offset="6" data-posts="3">Show More Articles</button>
<button id="scolltotop" class="btn btn-primary scrollToTop" style="display:none;">Back to Top</button>
[[!获取资源?
&父母=`10,22`
&深度=`999`
&限制=`6`
&偏移量=`0`
&includeTVs=`1`
&processTVs=`1`
&includeContent=`1`
&tpl=`infiniteHomePageTpl`
&sortby=`publishedon`
&showHidden=`1`
&hideContainers=`1`
]]
显示更多文章
回到顶端
为了简单起见,下面是代码片段和js:
<?php
$output = array(
'status' => 'success',
'msg' => 'message',
'data' => 'blaaaaaaaah',
'lastpost' => FALSE,
);
$properties = $scriptProperties['data'];
$modx->log(modX::LOG_LEVEL_ERROR,'Running processor: ajax.generic, scriptProperties = '. print_r($properties, TRUE));
$limit = $properties['limit'];
$parents = $properties['parents'];
$tpl = $properties['tpl'];
$offset = $properties['offset'];
$depth = $properties['depth'];
$sortby = $properties['sortby'];
$debug = $properties['debug'];
$showHidden = $properties['showHidden'];
$hideContainers = $properties['hideContainers'];
$modx->log(modX::LOG_LEVEL_ERROR, 'tpl = ' . $tpl);
$posts = $modx->runSnippet('getResources', array(
'parents' => $parents,
'depth' => $depth,
'limit' => $limit,
'offset' => $offset,
'includeTVs' => '1',
'processTVs' => '1',
'includeContent' => '1',
'tpl' => $tpl,
'debug' => $debug,
'sortby' => $sortby,
'showHidden' => $showHidden,
'hideContainers'=> $hideContainers,
));
$output['posts'] = '<div class="post-group" style="display:none" >' . $posts . '</div>';
if(strlen($posts) == 0){
$output['lastpost'] = TRUE;
}
$output = $modx->toJSON($output);
return $output;
Hi Sean,在集成代码的过程中,我在控制台中得到了以下信息:Object{status:“success”,msg:“message”,data:“blaaaaaaaah”,lastpost:true,posts:“}nodatalooks当时看起来像是在工作-您得到了带有~some~数据的默认成功数组,但可能runsnippet没有返回任何东西。嗯,奇怪。你有没有想过为什么runsnippet没有返回任何内容?不是真的-我在runsnippet中遇到的一个问题是它只返回字符串[没有数组、对象等],但这看起来不是问题所在-你有渲染的块,所以它正在做一些事情。在snippet函数外部构建数组并转储它,以便准确地看到传递的内容,然后查看是否可以说服get resources返回调试信息[不要指定块并将debug设置为1]或发布修改后的代码这是传递的Javascript:Object{snippet:“ajax分页”,limit:5,offset:0,parents:5,depth:999,sortby:“publishedon”,debug:1,tpl:“blog item”}
我得到一个“POST 200 OK”,所以数据看起来是发送的,但我得到的是返回的[object object](未定义)。
<?php
$output = array(
'status' => 'success',
'msg' => 'message',
'data' => 'blaaaaaaaah',
'lastpost' => FALSE,
);
$properties = $scriptProperties['data'];
$modx->log(modX::LOG_LEVEL_ERROR,'Running processor: ajax.generic, scriptProperties = '. print_r($properties, TRUE));
$limit = $properties['limit'];
$parents = $properties['parents'];
$tpl = $properties['tpl'];
$offset = $properties['offset'];
$depth = $properties['depth'];
$sortby = $properties['sortby'];
$debug = $properties['debug'];
$showHidden = $properties['showHidden'];
$hideContainers = $properties['hideContainers'];
$modx->log(modX::LOG_LEVEL_ERROR, 'tpl = ' . $tpl);
$posts = $modx->runSnippet('getResources', array(
'parents' => $parents,
'depth' => $depth,
'limit' => $limit,
'offset' => $offset,
'includeTVs' => '1',
'processTVs' => '1',
'includeContent' => '1',
'tpl' => $tpl,
'debug' => $debug,
'sortby' => $sortby,
'showHidden' => $showHidden,
'hideContainers'=> $hideContainers,
));
$output['posts'] = '<div class="post-group" style="display:none" >' . $posts . '</div>';
if(strlen($posts) == 0){
$output['lastpost'] = TRUE;
}
$output = $modx->toJSON($output);
return $output;
// infinite scrolling on homepage
// use: <button id="scroller" class="btn btn-primary load-more" data-parents="10,22" data-offset="0" data-posts="5">Show More Articles</button>
$('.load-more').click(function(e) {
var $this = $(this);
var offset = $this.data('offset'); // the current offset for get resources
var posts = $this.data('posts'); // the number of posts to get
var parents = $this.data('parents'); // the parent ids to pull resources from
var myProperties = {
snippet: 'infiniteScroll',
limit: posts,
offset: offset,
parents: parents,
depth: 999,
sortby: 'publishedon',
showHidden: 1,
debug: 1,
tpl: 'infiniteHomePageTpl',
hideContainers: 1
};
console.log('props = ' + JSON.stringify(myProperties));
$.ajax({
type: "POST",
url: "/ajax.processor",
data: myProperties,
dataType: "json",
success: function(response) {
var newposts = response.posts;
var $div = $("div#posts");
$div.append(newposts);
$div.find(".post-group:last").fadeIn();
$('body').stop().animate({scrollTop:$div.prop("scrollHeight") + $div.height()},1000);
if(response.lastpost){
console.log('nodata');
$this.attr('disabled', 'disabled');
$this.html('no more posts');
$('.scrollToTop').show();
}
$this.data('offset', (offset + posts));
},
error: function(response){
console.log(response);
},
}).fail(function(jqXHR,textStatus,errorThrown) {
console.log(errorThrown);
}); // ajax
}); // load more
// scroll back to top on finished resources.
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
<?php
//$modx->log(modX::LOG_LEVEL_ERROR,'Running processor: ajax.generic, snippet = '. print_r($_POST, TRUE));
$output = $modx->runSnippet($_POST['snippet'], array('data' => $_POST));
header('Content-type: application/json');
return $output;