Hy,我为新闻制作了一张幻灯片,问题是如何减少dathabase查询。。。或者如何压缩此代码。。。
http://s16.postimage.org/bswe0vrph/queries.jpg
<div id="featured" >
<ul class="ui-tabs-nav">
<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-1">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array(
\'post_type\' => \'stiri\',
\'showposts\' => 1,
\'offset\'=>0,
\'taxonomy\' => \'stire\',
\'stire\' => \'articole-speciale\'
)
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="#fragment-1"><img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=50&w=80&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
<?php endwhile; ?>
</li>
<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-2">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array(
\'post_type\' => \'stiri\',
\'showposts\' => 1,
\'offset\'=>1,
\'taxonomy\' => \'stire\',
\'stire\' => \'articole-speciale\'
)
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="#fragment-2"><img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=50&w=80&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
<?php endwhile; ?>
</li>
<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-3">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array(
\'post_type\' => \'stiri\',
\'showposts\' => 1,
\'offset\'=>2,
\'taxonomy\' => \'stire\',
\'stire\' => \'articole-speciale\'
)
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="#fragment-3"><img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=50&w=80&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
<?php endwhile; ?>
</li>
<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-4">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array(
\'post_type\' => \'stiri\',
\'showposts\' => 1,
\'offset\'=>3,
\'taxonomy\' => \'stire\',
\'stire\' => \'articole-speciale\'
)
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="#fragment-4"><img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=50&w=80&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
<?php endwhile; ?>
</li>
<li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-5">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array(
\'post_type\' => \'stiri\',
\'showposts\' => 1,
\'offset\'=>4,
\'taxonomy\' => \'stire\',
\'stire\' => \'articole-speciale\'
)
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="#fragment-5"><img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=50&w=80&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /><span><?php the_title(); ?></span></a>
<?php endwhile; ?>
</li>
</ul>
<!-- Stirea 1 -->
<div id="fragment-1" class="ui-tabs-panel" style="">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array(
\'post_type\' => \'stiri\',
\'showposts\' => 1,
\'taxonomy\' => \'stire\',
\'stire\' => \'articole-speciale\'
)
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="<?php the_permalink() ?>"><img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=325&w=664&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
<div class="info" >
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__(\'Stire %s\'), the_title_attribute(\'echo=0\')); ?>">...detalii</a></p>
</div>
<?php endwhile; ?>
</div>
<!-- Stirea 2 -->
<div id="fragment-2" class="ui-tabs-panel ui-tabs-hide" style="">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array(
\'post_type\' => \'stiri\',
\'showposts\' => 1,
\'offset\'=>1,
\'taxonomy\' => \'stire\',
\'stire\' => \'articole-speciale\'
)
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="<?php the_permalink() ?>"><img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=325&w=664&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
<div class="info" >
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__(\'Stire %s\'), the_title_attribute(\'echo=0\')); ?>">...detalii</a></p>
</div>
<?php endwhile; ?>
</div>
<!-- Stirea 3 -->
<div id="fragment-3" class="ui-tabs-panel ui-tabs-hide" style="">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array(
\'post_type\' => \'stiri\',
\'showposts\' => 1,
\'offset\'=>2,
\'taxonomy\' => \'stire\',
\'stire\' => \'articole-speciale\'
)
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="<?php the_permalink() ?>"><img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=325&w=664&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
<div class="info" >
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__(\'Stire %s\'), the_title_attribute(\'echo=0\')); ?>">...detalii</a></p>
</div>
<?php endwhile; ?>
</div>
<!-- Stirea 4 -->
<div id="fragment-4" class="ui-tabs-panel ui-tabs-hide" style="">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array(
\'post_type\' => \'stiri\',
\'showposts\' => 1,
\'offset\'=>3,
\'taxonomy\' => \'stire\',
\'stire\' => \'articole-speciale\'
)
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="<?php the_permalink() ?>"><img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=325&w=664&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
<div class="info" >
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__(\'Stire %s\'), the_title_attribute(\'echo=0\')); ?>">...detalii</a></p>
</div>
<?php endwhile; ?>
</div>
<!-- Stirea 5 -->
<div id="fragment-5" class="ui-tabs-panel ui-tabs-hide" style="">
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array(
\'post_type\' => \'stiri\',
\'showposts\' => 1,
\'offset\'=>4,
\'taxonomy\' => \'stire\',
\'stire\' => \'articole-speciale\'
)
);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<a href="<?php the_permalink() ?>"><img src="/scripts/timthumb.php?src=<?php the_field(\'imagine_stire\'); ?>&h=325&w=664&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
<div class="info" >
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<p><?php $excerpt = get_the_excerpt();echo string_limit_words($excerpt,30);?><a class="detalii" href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__(\'Stire %s\'), the_title_attribute(\'echo=0\')); ?>">...detalii</a></p>
</div>
<?php endwhile; ?>
</div>
</div>