【问题标题】:Display a custom script block through php on pagination page在分页页面上通过 php 显示自定义脚本块
【发布时间】:2013-09-16 19:42:29
【问题描述】:

我必须在分页页面的中心显示一个块 喜欢页面有 10 个项目的列表

我们如何在页面上将其拆分为 2 部分,以便在每 5 个项目之后 - 我可以显示一个启用 Javascript 的自定义块,以便将我们的自定义脚本放在那里

寻呼逻辑

   //logic of count

$model              = &$this->getModel();
$modelCategoryList  = &$this->getModel( 'list' );
$newslistTotal = $modelCategoryList->get_news_list_total();
$page = (isset($_REQUEST['page'])!="")? $_REQUEST['page'] : 1;
$records_per_page=10;               
$offset = ($page-1) * $records_per_page;

   //display count on the pager page based on logic

      $newslist = $modelCategoryList->get_news_list($offset,$records_per_page);         
    $this->assignRef('newslist'  , $newslist);

查看表单

if(count($this->newslist) >0){

foreach($this->newslist as $newslist)
{
    $list .='<h2><strong>'.$newslist->make.' - '.$newslist->model.'</strong></h2>
    <p>'.$newslist->n_month.' - '.$newslist->year.'</p>
    <p>'.$newslist->list_description.'</p>
    <p></p><hr/>';
        }
 }else{
$list='<div>No Listings.</div>';
  }
   ?>

      <?php echo $list?> 

通过上述逻辑 - 项目在页面上列出,并进一步使用寻呼机逻辑给出页码。

如何实现点赞 这样所有包含 10 个列表的页面 可以回显

      <?php echo $list1?> (of first 5 entries)

    <custom script> ........  </custom script>

      <?php echo $list2?> (of balance 5 entries)

编辑

【问题讨论】:

    标签: php pagination logic


    【解决方案1】:

    你可以使用模数。

    if ($i % 5 === 0) {
       // custom code
    }
    

    每次取模结果为 0(每 5 行)时都会显示自定义代码。

    【讨论】:

    • 您好 Elon,谢谢,但是我认为我的代码中存在问题,因为 $i 整数无法正常工作。已编辑问题。有没有办法用 $count 或通过 $newslist 来做,这样当计数达到 5 / 15 / 25 / 35 / 45 并继续等时,脚本标签可以显示在条目之后和之前 6 / 16 / 26 / 36 / 46 / 56th entry like
    • @RuchikaModi 不,要做到这一点,您必须像以前一样使用$i var 或将foreach 更改为for
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-20
    相关资源
    最近更新 更多