Products
GG网络技术分享 2025-03-18 16:12 0
wordpress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现
或者
type=postbypost:按最新文章排列
limit:限制文章数量最新20篇
format=custom:用来自定义这份文章列表的显示样式(fromat=custom也可以不要,默认以UL列表显示文章标题。)
通过WP的query_posts()函数也能调用最新文章列表的好处就是可以通过Loop控制显示。
上面代码的意思是 读取6篇文章,排除分类ID为10里面的文章
我们在WordPress CMS网站中常常看到同一分类调用不同的文章样式,前面几篇和后面的文章显示不同的样式。
通过以下代码即可实现这个功能:
<?phpquery_posts("showposts=2&cat=1");?><?phpwhile(have_posts()):the_post();?>
<divclass="category-item-top"><ahref="<?phpthe_permalink()?>"><imgsrc='<?phpechocatch_first_image()?>'border='0'width='120'height='90'alt='<?phpthe_title_attribute();?>'></a>
<h4><ahref="<?phpthe_permalink()?>"target="_blank"><?phpthe_title_attribute();?></a></h4>
<p><?phpechomb_strimwidth(strip_tags(apply_filters('the_content',$post->post_content)),0,80,"...");?></p>
</div>
<?phpendwhile;?>
<ulclass="indexList1">
<?phpquery_posts("showposts=3&cat=1&offset=2");?>
<?phpwhile(have_posts()):the_post();?>
<li><spanclass="articletitle"><ahref="<?phpthe_permalink()?>"targent="_blank"style="color:#F81F5A;"><?phpthe_title_attribute();?></a></span></li>
<?phpendwhile;?>
以上代码是调用分类id为1的列表
前面两篇文章是上面图片展示的样式,之后的文章以列表的形式显示!
Demand feedback