济南网站建设_济南小程序APP开发_济南网站设计公司_WordPress建站-云优网络
欢迎来到云优网络,本站提供专业的WordPress网站模板高端网站建设/网站定制设计/网站定制开发
其他行业: 学校培训 宠物动物 家政服务 建材装修 新闻信息 景区旅游 服装服饰 机械电子 汽车租车 手机站模板 法律律师 物流快递 淘宝客模板 生产制造 生活用品 其它行业 电器电气 电器维修 美容化妆 酒类食品 金融财经

热门网站模板

最新网站模板

Copyright @ 2024 云优网络 ICP备案编号:鲁ICP备18003982号-1
当前位置:首页 > 程序教程 > 正文
程序教程

WordPress文章列表可以调用吗?怎么操作

发布:云优网络 / 日期:2021-10-18 / 浏览:412

WordPress文章列表可以调用吗?这个当然是可以的,很多人在制作WordPress网站时,根据需要很多地方都会用到文章列表,如果手动去一个个添加会很麻烦,接下来教大家利用代码快速调用文章列表的方法。

1、调用网站最新文章,代码如下:

<?php

query_posts(‘showposts=10&orderby=new’); //showposts=10表示10篇

while(have_posts()): the_post();

?>

<li><a href=”<?php the_permalink(); ?>”target=”_blank”><?php the_title() ?></a></li> //这里可以写成你自己需要的样式

<?php endwhile; ?>

//这里可以写成你自己需要的样式

2、调用随机文章,复制代码代码如下:

<?php

query_posts(‘showposts=10&orderby=rand’); //showposts=10表示10篇

while(have_posts()): the_post();

?>

<li><a href=”<?php the_permalink(); ?>”target=”_blank”><?php the_title() ?></a></li> //这里可以写成你自己需要的样式

<?php endwhile; ?>

3、调用某个分类下的最新文章,代码如下:

<?php

query_posts(‘showposts=10&cat=1’); //cat=1为调用ID为1的分类下文章

while(have_posts()) : the_post(); ?>

<li><a href=”<?php the_permalink() ?>”title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>

<?php endwhile; ?>

4、排除某个分类下的文章,代码如下:

<?php

query_posts(‘showposts=10&cat=-1’); //cat=-1为排除ID为1的分类下文章

while(have_posts()) : the_post(); ?>

<li><a href=”<?php the_permalink() ?>”title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>

<?php endwhile; ?>

以上就是调用WordPress文章列表的方法,可以将例子中的代码结合起来达到你需要的效果。

Copyright @ 2024 云优网络      ICP备案编号:鲁ICP备18003982号-1