php Concrete5 Ajax页面列表 - 多重过滤器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Concrete5 Ajax页面列表 - 多重过滤器相关的知识,希望对你有一定的参考价值。

<?php defined('C5_EXECUTE') or die("Access Denied.");
// collect data from ajax post
$page = 1;
$page = $_POST['page'];
$rowperpage = 10;
$rowperpage = $_POST['perpage'];

// start output variable
$html = "";

// page list mirrors embedded page list including any filters
$pl = new PageList();
$pl->filterByCollectionTypeHandle('website');
$pagination = $pl->getPagination();
$pagination->setMaxPerPage($rowperpage)->setCurrentPage($page);
$pages = $pagination->getCurrentPageResults();

foreach ($pages as $page) {
//build page code as required
  $html .= '<li>'.$page->getCollectionName().'</li>';
}

// output to page
echo $html;

?>
<?php defined('C5_EXECUTE') or die("Access Denied.");
// Check for pagination
  $pge = 1;
  if ($_GET['ccm_paging_p']) { $pge = $_GET['ccm_paging_p']; }
// Start Page List
  $pl = new PageList();
  $pl->filterByCollectionTypeHandle('blog_post');
  $pl->filterByExcludePageList(false);
// Archive Page?
  $arch = "";
  if ($c->getCollectionTypeName() == 'Blog List') {
    $pl->filterByPath($c->getCollectionPath(), $includeAllChildren = true);
    $arch = $c->getCollectionPath();
  }
// User Page?
  $uid = "";
  if($c->getCollectionTypeName() == 'Bio'){
    $ownerID = $c->getCollectionUserID();
    $pl->filterByUserID($ownerID);
    $uid = $ownerID;
  }
// Tag Filter?
  $fltr = array();
  $request = Request::getInstance();
  $requestPath = $request->getPath();
  if (preg_match('/\/tag\//', $requestPath)) {
    $tagPosition = strpos($requestPath, '/tag/') + 5;
    $sTag = substr($requestPath, $tagPosition);
  }
  if (isset($sTag)) { // IF FILTERED!
    $pl->filterByTags($sTag);
    $pl->sortByRelevance();
    $fltr = $stack = array($sTag);
  } else {
    $pl->sortByPublicDateDescending();
  }
// Pagination for Ajax loading
  $pagination = $pl->getPagination();
  $pagination->setMaxPerPage(3)->setCurrentPage($pge);
// Get Pages
  $pages = $pagination->getCurrentPageResults();
  $tot = $pagination->getTotalResults();
  $pgs = $pagination->getTotalPages();
// Show Tag filter results
  if (isset($sTag)) {
    echo '<div class="result"><p><strong>'.$tot.'</strong> post';
    if ($tot !== 1) { echo 's'; }
    echo ' found in <strong>'.ucwords($sTag).'</strong></p></div>';
  }
// Show Page counter
  echo '<p>Page <span class="counter">'.$pge.'</span> of '.$pgs.'</p>';
// Show results
  if (!empty($pages)) {
    foreach ($pages as $page) {

// Link date to archive
      echo '<a href="/blog/'.$page->getCollectionDatePublicObject()->format('Y/m').'">';
      echo$page->getCollectionDatePublicObject()->format('jS F Y');
      echo '</a>';

// Link title to page      
      echo '<a href="'.$page->getCollectionLink().'">';
      echo $page->getCollectionName();
      echo '</a>';

// Show tags
      if ($page->getAttribute('tags')) {
        $tags = $page->getAttribute('tags');
        foreach($tags as $tags => $tag) {
          echo " $tag";
        }
      }

    }

// Pagination
    if ($pagecount > 1) {
      $options = array(
        'prev_message'        => '<',
        'next_message'        => '>',
      );
      echo $pagination->renderDefaultView($options);
    }

  }

// Loading animation
  echo '<p id="loading" class="text-muted text-center" style="display: none;">&nbsp;<br><strong><i class="fa fa-spinner fa-spin"></i> Loading...</strong></p>';
  
  ?>
  
<!-- Javascript Ajax Request  -->
  
<script>
$(function() {

  // hide pagination
  $('.ccm-pagination-wrapper').hide(); // Hide Manual Pagination

  //set vars
  var pge = <?php echo json_encode($pge); ?>;
  var pgs = <?php echo json_encode($pgs); ?>;
  var uid = <?php echo json_encode($uid); ?>;
  var arch = <?php echo json_encode($arch); ?>;
  var fltr = <?php echo json_encode($fltr); ?>;
  var tgclk = false;

  $(window).scroll(function(){ // Scroll Pagination
    var nearToBottom = 200;
    var position = $(window).scrollTop() + $(window).height();
    var bottom = $(document).height() - $(window).height();

    if (position >= bottom) {
      if(pge < pgs) {
        $('#loading').show();
        pge = pge+1;
        $.ajax({
          url: '/ajax', // single page address
          type: 'post',
          data: {
            pge:pge,
            pgs:pgs,
            uid:uid,
            arch:arch,
            fltr:fltr,
            tgclk:tgclk
          },
          success: function(response){
            $('.counter').text(pge);
            $('#loading').hide();
            $(".return").append(response).show().fadeIn("slow");

          }
        });
      }
    }
  });

// tag click

// reset to page 1
// remove any tag heading
// get new result total, page total from returned result
// remove new result total, page total from page

});
</script>
  
  
  
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>

以上是关于php Concrete5 Ajax页面列表 - 多重过滤器的主要内容,如果未能解决你的问题,请参考以下文章

PHP 显示页面属性 - Concrete5

在Ubuntu 16.04上安装Concrete5

php Concrete5区域功能

php Concrete5属性函数

PHP 添加Autonav Block - Concrete5

PHP 如果Site处于编辑模式,请执行此操作 - Concrete5