我有大约10k篇帖子,我制作了一个页面,列出了所有帖子,但每54篇帖子都会分页。它在6.730秒内提供131个查询,加载速度非常慢。有没有办法让它加载得更快?
这是我的功能页面
<?php
/* Custom code goes below this line. */
add_theme_support( \'post-formats\', array( \'aside\', \'gallery\' ) );
add_filter( \'use_default_gallery_style\', \'__return_false\' );
/* Add the Javascript */
$path = get_stylesheet_directory_uri() .\'/js/\';
wp_enqueue_script(\'post-navigation\', $path.\'jquery.navigate.js\', array(\'jquery\'));
function catch_that_image() {
global $post, $posts;
$first_img = \'\';
ob_start();
ob_end_clean();
$transformed_content = apply_filters(\'the_content\',$post->post_content);
$output = preg_match_all(\'/<img.+src=[\\\'"]([^\\\'"]+)[\\\'"].*>/i\', $transformed_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
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";
}
}
// This function should go in functions.php
function mam_posts_where ($where) {
global $mam_global_where;
if ($mam_global_where) $where .= " $mam_global_where";
return $where;
}
add_filter(\'posts_where\',\'mam_posts_where\');
/* Custom code goes above this line. */
?>
这是我的页面模板
<?php
/*
Template Name: List
*/
?>
<?php get_header(); ?>
<div id="container">
<div id="content2" role="main">
<?php $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array( \'post_type\' => \'post\', \'posts_per_page\' => 54, \'paged\' => $paged );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); ?>
<div class="seriesbox">
<a class="size-thumbnail" href="<?php the_permalink(); ?>"><img src="<?php echo catch_that_image() ?>"/></a>
<div class="seriestitle"><h2><?php the_title() ?></h2></div>
</div>
<?php endwhile; ?>
<!-- then the pagination links -->
<?php if (function_exists("pagination")) {
pagination($additional_loop->max_num_pages);
} ?>
</div><!-- #content -->
</div><!-- #container -->
<?php get_footer(); ?>