建站教程

建站教程

Products

当前位置:首页 > 建站教程 >

wordpress免插件调用最新文章的四种方法(wordpress 调用分类列表 不同的列表样式)

GG网络技术分享 2025-03-18 16:12 0


wordpress免插件调用最新文章的四种方法

方法一、wp_get_archvies函数

wordpress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现

或者

type=postbypost:按最新文章排列

limit:限制文章数量最新20篇

format=custom:用来自定义这份文章列表的显示样式(fromat=custom也可以不要,默认以UL列表显示文章标题。)

方法二、query_posts()函数

通过WP的query_posts()函数也能调用最新文章列表的好处就是可以通过Loop控制显示。

上面代码的意思是 读取6篇文章,排除分类ID为10里面的文章

三、使用WP_Query函数

四、使用 get_results 函数

wordpress 调用分类列表 不同的列表样式

我们在WordPress CMS网站中常常看到同一分类调用不同的文章样式,前面几篇和后面的文章显示不同的样式。

3422.JPG

通过以下代码即可实现这个功能:

<?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