我有页面显示照片和带分页的视频(每页5个项目)我创建了两个按钮(照片和视频),通过使用show和hide jquery功能分别显示每个按钮,但问题是当我选择视频时它确定并显示视频,但当我选择下一页时,它会指示并显示下一张照片而不是视频:
<div id="photo">
{if $mediaRows}
{include file="paging.tpl" paging=$mediaPaging}
<div id="mediaListContainer">
{foreach $mediaArray as $media}
{include file='contributor.media.container.tpl'}
{/foreach}
</div>
{include file="paging.tpl" paging=$mediaPaging}
{else}
<p class="notice">{$lang.noMediaAlbum}</p>
{/if}
</div>
<div id="video" hidden>
{if $mediaRowsV}
{include file="paging.tpl" paging=$mediaPagingV}
<div id="mediaListContainer">
{foreach $mediaArrayV as $media}
{include file='contributor.media.container.tpl'}
{/foreach}
</div>
{include file="paging.tpl" paging=$mediaPaging}
{else}
<p class="notice">{$lang.noMediaAlbum}</p>
{/if}
</div>
我知道发生这种情况是因为我把div视频隐藏但我这样做是因为我需要我的默认值(当用户获取页面时)是照片。 我怎么能解决这个问题。有什么想法吗?
答案 0 :(得分:0)
我相信这可能是你正在寻找的东西,它适用于BootStrap(所以你可能需要包含文件并且是为bs 1.11.4编写的),但这里是我为分页编写的类:
<?php
class Paginator {
/**
* @var mysqli
*/
private $_conn;
private $_limit;
private $_page;
private $_query;
private $_total;
public function __construct( $conn, $query ) {
$this->_conn = $conn;
$this->_query = $query;
$rs= $this->_conn->query( $this->_query );
$this->_total = $rs->num_rows;
}
public function get_data( $limit = 10, $page = 1 ) {
$this->_limit = $limit;
$this->_page = $page;
if ( $this->_limit == 'all' ) {
$query = $this->_query;
} else {
$query = $this->_query . " LIMIT " . ( ( $this->_page - 1 ) * $this->_limit ) . ", " . $this->_limit . ";";
}
$rs = $this->_conn->query( $query );
while ( $row = mysqli_fetch_assoc($rs) ) {
$results[] = $row;
}
$result = new stdClass();
$result->page = $this->_page;
$result->limit = $this->_limit;
$result->total = $this->_total;
$result->data = $results;
return $result;
}
public function create_links( $links, $list_class ) {
if ( $this->_limit == 'all' ) {
return '';
}
$last = ceil( $this->_total / $this->_limit );
$start = ( ( $this->_page - $links ) > 0 ) ? $this->_page - $links : 1;
$end = ( ( $this->_page + $links ) < $last ) ? $this->_page + $links : $last;
$html = '<ul class="' . $list_class . '">';
$class = ( $this->_page == 1 ) ? "disabled" : "";
if ($this->_page > 1) {
$html .= '<li class="' . $class . '"><a href="?page=pagelimit=' . $this->_limit . '&_page=' . ( $this->_page - 1 ) . '">«</a></li>';
}
if ( $start > 1 ) {
$html .= '<li><a href="?page=page&limit=' . $this->_limit . '&_page=1">1</a></li>';
$html .= '<li class="disabled"><span>...</span></li>';
}
for ( $i = $start ; $i <= $end; $i++ ) {
$class = ( $this->_page == $i ) ? "active" : "";
$html .= '<li class="' . $class . '"><a href="?pagepage&limit=' . $this->_limit . '&_page=' . $i . '">' . $i . '</a></li>';
}
if ( $end < $last ) {
$html .= '<li class="disabled"><span>...</span></li>';
$html .= '<li><a href="?page=pagelimit=' . $this->_limit . '&_page=' . $last . '">' . $last . '</a></li>';
}
$class = ( $this->_page == $last ) ? "disabled" : "";
if ($this->_limit < $this->_total) {
$html .= '<li class="' . $class . '"><a href="?page=page&limit=' . $this->_limit . '&_page=' . ( $this->_page + 1 ) . '">»</a></li>';
}
$html .= '</ul>';
return $html;
}
}
?>
在create_links
函数中,您将?page = page替换为您需要的任何内容,它对我来说非常完美,并希望它也适合您!