WordPress plugin wp-pager
效果

wp-pager.php代码
<?php
/*
Plugin Name: wp-pager
Plugin URI: http://coffelius.bloggear.net
Description: Extended pager
Author: Gabriel Ortega
Author URI: http://coffelius.bloggear.net
*/
function wp_pager($paglabel='Pag: ', $prelabel='Anterior', $nxtlabel='Siguiente', $msglabel='Mostrando posts %f al %l de %t', $show_pages=true) {
global $request, $posts_per_page, $wpdb, $paged;
if (! is_single()) {
if (get_query_var('what_to_show') == 'posts') {
preg_match('#FROM (.*) GROUP BY#', $request, $matches);
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
$max_page = ceil($numposts / $posts_per_page);
} else {
$max_page = 999999;
}
if ($max_page > 1) {
echo '<div class="wp-pager">';
echo $paglabel;
if(!$paged) $paged=1;
$first=($paged-1)*$posts_per_page+1;
$last=$first+$posts_per_page-1;
if($last>$numposts) $last=$numposts;
previous_posts_link($prelabel);
if($show_pages)
for($i=1;$i<=$max_page;$i++) {
if($i!=$paged) {
echo ' <a href="';
echo get_pagenum_link($i);
echo '">'.$i.'</a> ';
}
else echo '<b>'.$i.'</b>';
}
next_posts_link($nxtlabel, $max_page);
$msglabel=str_replace('%f', $first, $msglabel);
$msglabel=str_replace('%l', $last, $msglabel);
$msglabel=str_replace('%t', $numposts, $msglabel);
echo "<br/><div>$msglabel</div>";
echo '</div>';
}
}
}
?>
/*
Plugin Name: wp-pager
Plugin URI: http://coffelius.bloggear.net
Description: Extended pager
Author: Gabriel Ortega
Author URI: http://coffelius.bloggear.net
*/
function wp_pager($paglabel='Pag: ', $prelabel='Anterior', $nxtlabel='Siguiente', $msglabel='Mostrando posts %f al %l de %t', $show_pages=true) {
global $request, $posts_per_page, $wpdb, $paged;
if (! is_single()) {
if (get_query_var('what_to_show') == 'posts') {
preg_match('#FROM (.*) GROUP BY#', $request, $matches);
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
$max_page = ceil($numposts / $posts_per_page);
} else {
$max_page = 999999;
}
if ($max_page > 1) {
echo '<div class="wp-pager">';
echo $paglabel;
if(!$paged) $paged=1;
$first=($paged-1)*$posts_per_page+1;
$last=$first+$posts_per_page-1;
if($last>$numposts) $last=$numposts;
previous_posts_link($prelabel);
if($show_pages)
for($i=1;$i<=$max_page;$i++) {
if($i!=$paged) {
echo ' <a href="';
echo get_pagenum_link($i);
echo '">'.$i.'</a> ';
}
else echo '<b>'.$i.'</b>';
}
next_posts_link($nxtlabel, $max_page);
$msglabel=str_replace('%f', $first, $msglabel);
$msglabel=str_replace('%l', $last, $msglabel);
$msglabel=str_replace('%t', $numposts, $msglabel);
echo "<br/><div>$msglabel</div>";
echo '</div>';
}
}
}
?>
调用
<?php wp_pager('Pag: ', 'Anterior', 'Siguiente', 'Mostrando posts %f al %l de %t', true); ?>
Tags:
andy大哥
怎么我装这个实现不了呢?
调用要放在哪里?
上面的代码寸成一个文件放在根目录下面么?
另:请问大哥的google广告条怎么放的?默认的wordpress可以放么?还是需要另外的插件,比如后台可视化编辑器,...
Reply
我在index.php里增加后出现此错误:
« Previous entries · Project-Id-Version: WordPress Report-Msgid-Bugs-To: FULL NAME POT-Creation-Date: 2004-12-21 02:45:29.728614 PO-Revision-Date: 2005-03-16 09:37+0800 Last-Translator: peter Language-Team: Chinese (China) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rosetta-Version: 0.1 Plural-Forms: nplurals=1; plural=0 X-Generator: Rosetta (http://launchpad.ubuntu.com/rosetta/) Project-Id-Version: WordPress Report-Msgid-Bugs-To: FULL NAME POT-Creation-Date: 2004-12-21 02:45:29.728614 PO-Revision-Date: 2005-03-16 09:37+0800 Last-Translator: peter Language-Team: Chinese (China) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rosetta-Version: 0.1 Plural-Forms: nplurals=1; plural=0 X-Generator: Rosetta (http://launchpad.ubuntu.com/rosetta/)
Reply
该分页plugin我未测试,呵呵
google广告的放置可以直接放你的代码里,也可以用plugin
Reply
[...] 刚装好自己的WP站点,常在网上搜索相关信息。以下是一些自己认为还不错的站点和页面:1、不错的Themes下载页面,有界面预览:http://www.alexking.org/software/wordpress/theme_browser.php2、风言疯语的WordPress插件搜集:http://www.kuangfeng.cn/blog/?p=93、中文WordPress Planet:http://yanfeng.org/wp/4、WordPress中文:以论坛形式搭建,目前人气还不是很旺,但论坛分类结构比较清楚,慢慢人气足后,会是一个不错的去处。http://wordpress.org.cn5、Andy’s Blog里的Wp专题:http://www.21andy.com/blog/category/technology/wordpress/ [...]
存为wp-pager.php放到plugin目录下即可
Reply
我未测试,呵呵
Reply
呵呵
Reply