我正在一个网站上工作,我们将从菜单中引入下拉面板,它将显示网站上各种标签的缩略图。
每个面板的左栏显示一篇特色文章,右栏显示6个缩略图;在每个选项卡上,我将执行两个wp\\U查询循环,第一个循环显示特色帖子图像,第二个循环显示6个缩略图(不包括特色帖子)。
我想知道这是否是最有效的方式,因为有10个选项卡,所以主菜单中有20个wp\\u query的用法。
以下选项卡之一的示例代码:
<div class="displaymenu"><div class="menucontent">
<div class="leftdisplaymenu padding">
<?php
global $quote_id;
$quote_id=array(); // setup an array to store post ids to exclude from future queries
$argsformainquotes=array(
\'posts_per_page\' => \'1\',
\'post_status\' => \'publish\',
\'tag\' => \'quotes\',
);
$mainquotes = new WP_Query($argsformainquotes);
while ($mainquotes->have_posts()) : $mainquotes ->the_post();
$idforquote=get_the_id(); $quote_id[]=$idforquote; // add the id of this post to exclusion array
$post_thumbnail_id = get_post_thumbnail_id();
$post_thumbnail_url = wp_get_attachment_image_src( $post_thumbnail_id,\'bigfeature\'); ?><div class="mainimg"><a href="<?php the_permalink();?>" target="_blank"><img src="<?php echo $post_thumbnail_url[0];?>" alt=" <?php the_title();?>" class="thumblist" height="240" width="240" /></a><div class="imgtitle"><a href="<?php the_permalink();?>" title="<?php the_title();?>" class="tablinktitles"><?php the_title();?></a></div><br /><?php $small_excerpt=get_the_excerpt();echo substr($small_excerpt,0,100);?><br /><br /><a href="<?php the_permalink();?>" class="tablinktitles">read more...</a></div><?php endwhile;?>
<div></div></div>
<div class="rightdisplaymenu"><ul><?php $argsforquotes=array(
\'posts_per_page\' => \'6\',
\'post_status\' => \'publish\',
\'tag\' => \'quotes\',
\'post__not_in\' => $quote_id,
);
$quotes = new WP_Query($argsforquotes);
while ($quotes->have_posts()) : $quotes ->the_post();?>
<li><?php
$post_thumbnail_id = get_post_thumbnail_id();
$post_thumbnail_url = wp_get_attachment_image_src( $post_thumbnail_id,\'smallfeature\' ); ?><a href="<?php the_permalink();?>" target="_blank"><img src="<?php echo $post_thumbnail_url[0];?>" alt=" <?php the_title();?>" height="140" width="140" class="thumblist" /></a><br /><a href="<?php the_permalink();?>"><?php $trunctitle=get_the_title();echo substr($trunctitle,0,20);?>...</a></li><?php endwhile;?> </ul><div class="furtherlink"><a href="http://www.aplacetolovedogs.com/tag/quotes/" title="More of Your Dog Quotes">More Quotes...</a></div></div>
</div></div>