如何在我的 Ziggeo 应用程序中使用分页显示我的所有视频?

How to make visible all my videos with pagination in my Ziggeo application?

所以我需要 Ziggeo 用户的帮助。我已经在我的 ziggeo 服务器中注册了 8 个视频,现在我想将它们显示在除以每页 2 个视频的页面中。 这是我写的,但不幸的是它没有显示任何视频,但编译器没有说任何错误。

<?php include('./ziggeo/pagination.class.php');?>
<?php $myvideos = $ziggeo->videos();
$myarray = array($myvideos);?>
<div class="gallery">
<?php if(count($myarray)){
$pagination = new pagination($myarray, (isset($_GET['page'])?$_GET['page']:1), 3);
$videos = $pagination->getResults();
if(count($videos)!=0) {
echo $pageNumbers = '<h2>'.$pagination->getLinks().'</h2>';
foreach ($videos as $video) {?>
<div class="wall-of-videos-container">
<ziggeo ziggeo-video="<?= $video->token ?>"
ziggeo-width=320 ziggeo-height=240 ziggeo-popup> </ziggeo>
<?= date("Y-m-d h:i a", $video->created) ?>
&middot;<?= $video->duration ?> seconds</div>
 <? } echo $pageNumbers; } } ?>
 </div><!-- End Gallery -->

我包含了 Ziggeo 配置所需的所有文件。 谁能帮我?非常感谢!

如果没有看到 'pagination.class.php' 文件内容和您正在创建的输出,很难知道出了什么问题,但是要使用 Ziggeo PHP SDK 在 PHP 中创建分页,您会做这样的事情:

<?php
  require_once('Ziggeo.php');
  $ziggeo = new Ziggeo('YOUR TOKEN', 'YOUR PRIVATE KEY', 'YOUR ENCRYPTION KEY');
?>

现在查看您的代码,似乎这是您没有正确进行的调用。要获取视频,您应该拨打以下电话:

<?php $myvideos = $ziggeo->videos()->index(); ?>

请记住,默认情况下您最多只能获取 50 个视频,因此如果您希望拥有更多视频,则应设置限制参数。

您可以设置limitskipreversestatestags

如果您想获得最多 100 个视频(每次通话的上限),您可以这样做:

<?php
  $myArguments = array('limit' => 100);
  $myvideos = $ziggeo->videos()->index($myArguments);
?>

现在要列出它们,您可以这样做:

<?php
  foreach ($myvideos as $video) {
    ?>
      <ziggeo ziggeo-video="<?php echo $video->token; ?>" ziggeo-width=320 ziggeo-height=240 ziggeo-popup></ziggeo>
    <?php
  }
?>
  • 您可以在 foreach 之前使用 count($myvideos) 添加一个检查,但是不需要。

一般来说,要创建一个每页包含 2 个视频的页面,您可以使用如下内容:

<?php
  $i = 0; //to have two videos per page
  $j = 0; //to see how many we have
  foreach ($myvideos as $video) {
      $j++;
      if($i === 0) { ?>
        <div class="gallery_page">
      <?php } ?>
      <ziggeo ziggeo-video="<?php echo $video->token; ?>" ziggeo-width=320 ziggeo-height=240 ziggeo-popup></ziggeo>
    <?php
      $i++;
      if($i === 2) { ?>
        </div>
        <div class="page_number"><?php echo $j/2; ?> </div>
      <?php
        $i = 0;
      }
  }
  if($i !== 0) {
      ?>
        <div class="page_number"><?php echo (($j-1)/2)+1; ?> </div>
      <?php
  }
?>
  • 值得指出的是,上面的代码不是一个完整的分页系统 - 它只是一个简单的示例,向您展示了如何做到这一点,但是需要对其进行自定义和进一步处理以匹配画廊风格,和类似的。

查看您的代码,我认为它应该可以使用如下代码:

<?php
  include('./ziggeo/pagination.class.php');
  $myvideos = $ziggeo->videos()->index();
?>
<div class="gallery">
<?php
  if(count($myvideos)) {
    $pagination = new pagination($myarray, (isset($_GET['page']) ? $_GET['page']:1), 3);
    $videos = $pagination->getResults();
    if(count($videos)!=0) {
      echo $pageNumbers = '<h2>'.$pagination->getLinks().'</h2>';
      foreach ($videos as $video) { ?>
        <div class="wall-of-videos-container">
        <ziggeo ziggeo-video="<?php echo $video->token; ?>" ziggeo-width=320 ziggeo-height=240 ziggeo-popup></ziggeo>
        <?php echo date("Y-m-d h:i a", $video->created); ?>
        &middot;<?php echo $video->duration; ?> seconds</div>
     <?php } echo $pageNumbers;
     }
  } ?>
</div><!-- End Gallery -->

不过我确实假设您在将显示画廊的页面的 HTML HEAD 中设置了 headers:

<link rel="stylesheet" href="//assets-cdn.ziggeo.com/v1-latest/ziggeo.css" /> 
<script src="//assets-cdn.ziggeo.com/v1-latest/ziggeo.js"></script>
<script type="text/javascript">ZiggeoApi.token="YOUR TOKEN"</script>

如果不存在,HTML 代码将从上面的 PHP 代码创建,但是由于未在客户端加载 Ziggeo 框架,您的视频将不会显示。

更新 (2016/05/31)

由于以上只是执行此操作的一般方法,因此不包括 CSS 和 JavaScript。

因此,我添加了可以使用的完整代码,因为它显示了另一种收集页码的方法并保留上面的代码,以便有人可以看到两者。

<script type="text/javascript">
  //Basic code needed to switch pages
  var currentPage = 1;
  function showPage(number) {
    //If we are on the same page as the selected one, we just break away from the function, so that we do not hide the same.
    if(currentPage === number) { return false; }

    var toShow = document.getElementById('page_' + number);
    var toHide = document.getElementById('page_' + currentPage);

    toShow.style.display = 'block';
    toHide.style.display = 'none';

    currentPage = number;
  }
</script>

<style type="text/css">
  /* Code to hide the pages (all) and show first one only, as well as a bit of styling so that it has some basic frame */
  .gallery_page > ziggeo {
    float: left;
  }
  .gallery_page {
    background-image: linear-gradient(-45deg, lightGray, white);
    border-radius: 10px;
    box-shadow: 0 0 2px gray;
    box-sizing: border-box;
    display: none;
    min-height: 400px;
    margin: 20px 0;
    padding: 40px;
    width: 720px;
  }
  .gallery_page:first-child {
    display: block;
  }
  .page_number {
    box-shadow: 0 0 3px gray;
    float: left;
    margin: 0 4px;
    text-align: center;
    width: 2em;
  }
</style>

<div class="gallery">
  <?php
  //How many videos per page do we want to have?
  $numberOfVideos = 2;
  //How many videos was there in total?
  $totalNumberOfVideos = 0; //only if we need it for something later on
  //How many videos are approved / are shown
  $totalNumberOfApprovedVideos = 0; //only if we need it for something later on
  //which page are we working on?
  $currentPage = 1;
  //Will serve as buffer for page number elements
  $pageNumbers = '';
  //temporary videos counter
  $i = 0;

  foreach ($myvideos as $video) {
    //to only show approved videos
    if($video->approved === true) {
      if($i === 0) { ?>
        <div class="gallery_page" id="page_<?php echo $currentPage; ?>">
      <?php } ?>

      <ziggeo ziggeo-video="<?php echo $video->token; ?>" ziggeo-width=320 ziggeo-height=240 ziggeo-popup></ziggeo>

      <?php

      $i++;
      if($i === $numberOfVideos) { ?>
        <br style="float:none; clear:left;">
        </div>
        <?php
        $pageNumbers .= '<div onclick="showPage(' . $currentPage . ');" class="page_number">' . $currentPage . '</div>';
        $currentPage++;
        $i = 0;
      }

      $totalNumberOfApprovedVideos++;
      $totalNumberOfVideos++;
    }
    else {
    //$video->moderation_reason
    //If you want to check if there was a reason why the video was not approved, you can check the above, or alternatively, you could do something else at this point.
      $totalNumberOfVideos++;
    }
  }
  if($i !== 0) {
    $pageNumbers .= '<div onclick="showPage(' . $currentPage . ')" class="page_number">' . $currentPage . '</div>';
  }
  ?>
</div><!-- End Gallery -->

<?php echo $pageNumbers; ?>

<?php
  //This is not needed for pagination to work, however you might want to show it, etc
  echo '<br><br>';
  echo 'Approved videos: ' . $totalNumberOfApprovedVideos . '<br>';
  echo 'Total videos: ' . $totalNumberOfVideos . '<br>';
  echo 'Total number of pages: ' . $currentPage . '<br>';
  echo $numberOfVideos . ' videos per page<br>';
?>
  • 值得指出的是,这只是一个框架 - 因此前面提到的代码将像后续代码一样工作,但是两者都需要额外的样式和代码才能使其看起来漂亮并按我们想要的方式运行.

添加下面的java脚本后:

<script type="text/javascript">
var currentPage = 1;
function showPage(number){
var toShow = document.getElementById('page_' + number);
var toHide = document.getElementById('page_' + currentPage);
toShow.style.display = 'block';
toHide.style.display = 'none';
currentPage = number;}
</script>

以及对 div 画廊的正确引用,现在一切正常。谢谢贝恩。