如何使用PHP对新闻进行分页 [英] How to make a pagination for news using PHP
本文介绍了如何使用PHP对新闻进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这个php类作为模板引擎:
hi , i'm using this php class for template engine :
<?php
class Template {
protected $file;
protected $values = array();
public function __construct($file) {
$this->file = $file;
}
public function set($key, $value) {
$this->values[$key] = $value;
}
public function output() {
if (!file_exists($this->file)) {
return "Error loading template file ($this->file).<br />";
}
$output = file_get_contents($this->file);
foreach ($this->values as $key => $value) {
$tagToReplace = "[@$key]";
$output = str_replace($tagToReplace, $value, $output);
}
return $output;
}
static public function merge($templates, $separator = "\n") {
$output = "";
foreach ($templates as $template) {
$content = (get_class($template) !== "Template")
? "Error, incorrect type - expected Template."
: $template->output();
$output .= $content . $separator;
}
return $output;
}
public function newConnection($table,$name,$w,$wt){
$Query = mysql_query("SELECT * FROM {$table} WHERE {$w} = {$wt} ORDER BY id DESC");
$Arrays.$name = array();
while($row = mysql_fetch_array($Query,MYSQL_ASSOC)){
$Arrays.$name[] = $row;
}
}
}
?>
以及将数据作为index.php获取的方法:
and this methods to get data as index.php :
<?php
// Start POSTS
$postQuery = mysql_query("SELECT * FROM posts ORDER BY id DESC");
$postArrays = array();
while($rows = mysql_fetch_array($postQuery,MYSQL_ASSOC)){
$postArrays[] = $rows;
}
foreach($postArrays as $post) {
$row = new Template("{$tpl_dir}/post.tpl");
foreach ($post as $key => $value) {
$row->set($key, $value);
}
$postsTemplates[] = $row;
}
$postsContents = Template::merge($postsTemplates);
$header = new Template("{$tpl_dir}/header.tpl");
$header->set("title",$stitle);
$header->set("stylesheet","{$tpl_dir}/style.css");
$sidebar = new Template("{$tpl_dir}/sidebar.php");
ob_start(); getCount();
$sidebar->set("static",ob_get_clean());
ob_start(); getCat();
$sidebar->set("category", ob_get_clean());
$ads = new Template("{$tpl_dir}/ads.tpl");
$ads->set("tempurl",$tpl_dir);
$footer = new Template("{$tpl_dir}/footer.tpl");
$index = new Template("{$tpl_dir}/index.tpl");
$index->set("header", $header->output());
$index->set("ads", $ads->output());
$index->set("sidebar", $sidebar->output());
$index->set("posts", $postsContents);
$index->set("footer", $footer->output());
echo $index->output();
?>
和此文件作为主要设计:
and this file as post main design :
<article class="post">
<div class="wrapper">
<header><span>[@title]</span>
<ul class="post-info">
<li class="date">[@pdate]</li><li class="category">[@category]</li>
</ul>
</header>
<div class="pbod">
[@content]
</div>
<footer>
<a href="more.php?id=[@id]" title="[@title]" class="more">ادامه مطلب</a>
</footer>
</div>
</article>
但是我不知道如何对这个新闻进行分页,我知道如何在php中对它进行分页,但我不知道如何在模板类中对它进行分页!谁可以帮助我?!
我尝试过的事情:
i不能尝试任何东西,因为我最近开始学习php
but i don't know how to make a pagination for this news , i know how to paginate it in php, but i don't know how to paginate it in template class!!! so who can help me?!
What I have tried:
i can't try any thing , because i have started learning php recently
推荐答案
file ;
protected
file; protected
values = array();
public function __construct(
values = array(); public function __construct(
file){
这篇关于如何使用PHP对新闻进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文