我只是想问一下,如何在此代码中添加分页:
<?php if ( get_option(\'webly_display_media\') == \'on\' ){ ?>
<div id="recent-projects">
<div id="recent-projects-right">
<div id="recent-projects-content" class="clearfix">
<?php
$args=array(
\'showposts\' => \'7\',
\'category__not_in\' => get_option(\'webly_exlcats_media\')
);
query_posts($args);
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$width = 140;
$height = 72;
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,\'project-image\',$titletext,$titletext,true,\'Media\');
$thumb = $thumbnail["thumb"];
$et_medialink = get_post_meta($post->ID,\'et_medialink\',true) ? get_post_meta($post->ID,\'et_medialink\',true) : \'\';
$et_videolink = get_post_meta($post->ID,\'et_videolink\',true) ? get_post_meta($post->ID,\'et_videolink\',true) : \'\';
?>
<div class="project">
<?php if ( $et_medialink <> \'\' ) { ?>
<a href="<?php echo $et_medialink; ?>">
<?php } elseif ( $et_videolink <> \'\' ) { ?>
<a href="<?php echo $et_videolink; ?>" rel="prettyPhoto[media]" class="et-video" title="<?php echo $titletext; ?>">
<?php } else { ?>
<a href="<?php echo $thumbnail["fullpath"]; ?>" rel="prettyPhoto[media]" title="<?php echo $titletext; ?>">
<?php } ?>
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, \'project-image\'); ?>
<span class="zoom-icon"></span>
<span class="project-overlay"></span>
</a>
</div> <!-- end .project -->
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
</div> <!-- end #recent-projects-content -->
</div> <!-- end #recent-projects-right -->
</div> <!-- end #recent-projects -->
我的帖子有一个特色视频,目前该代码根据类别显示5个特色视频。问题是,我在该类别中已经有11篇帖子,但主题只能显示5篇帖子,所以我想对此进行分页。你能帮帮我吗?这是开发网站
http://dev.freelanceu.net/mjl/fitnessadventure/. 您可以在内容底部、页脚之前看到上述代码。
最合适的回答,由SO网友:AndrettiMilas 整理而成
将此添加到函数。php:
// Pagination
function pagination($pages = \'\', $range = 4)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == \'\')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class=\\"pagination\\"><span>Page ".$paged." of ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href=\'".get_pagenum_link(1)."\'>« First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href=\'".get_pagenum_link($paged - 1)."\'>‹ Previous</a>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class=\\"current\\">".$i."</span>":"<a href=\'".get_pagenum_link($i)."\' class=\\"inactive\\">".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href=\\"".get_pagenum_link($paged + 1)."\\">Next ›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href=\'".get_pagenum_link($pages)."\'>Last »</a>";
echo "</div>\\n";
}
}
然后使用以下方法获取分页链接:
<?php if (function_exists("pagination")) {
pagination($loop->max_num_pages);
} ?>