当前位置:首页 > 电脑知识 > 正文内容

全程干货(wordpress如何添加栏目)wordpress调用指定文章,wordpress如何调用栏目中最新文章,wordpress如何调用栏目中最新文章,

sauo3年前 (2022-12-15)电脑知识108

wordpress博客的侧边栏基本上都带有最新文章列表和随机文章的小工具功能。那么wordpress是如何来调用最新文章呢?

方法一:通过标签wp_get_archvies来实现(WordPress最新文章调用)

<?php get_archives(postbypost,10);?> (显示10篇最新更新文章) <?php wp_get_archives(type=postbypost&limit=20&format=custom);?>

后面这个代码显示你博客中最新的20篇文章,参数详解如下:

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

方法二:通过WP的query_posts()函数

通过wordpress的query_posts()函数来调用最新文章列表,虽然代码会比较多一点,但可以更好的控制Loop的显示,比如你可以设置是否显示摘要。代码如下:

<?php query_posts(posts_per_page=8&caller_get_posts=1);?><?php while(have_posts()): the_post();?><li> <a target="_blank" href="<?php the_permalink();?>" title="<?php the_title();?>" class="title"><?php echo cut_str($post->post_title,34);?></a></li><?php endwhile;?> //wordpress文章列表默认是按最新文章显示,posts_per_page=8表求显示8遍,caller_get_posts=1表示如果有置顶文章,可置顶1遍,其它按最新显示

如何调用单独的栏目名调用最新内容,代码如下:

<?php $cmntCnt =1; $cat=get_category_by_slug(news);?><?php $posts = get_posts("category=$cat->term_id&numberposts=3");?><?php if( $posts ):?><?php foreach( $posts as $post ): setup_postdata( $post );?><li><h6class="wow fadeInUp"data-wow-delay="0.2s"><a href="<?php the_permalink()?>" title="<?php the_title();?>"><?php echo cut_str($post->post_title,38);?></a></h6><spanclass="wow fadeInUp"data-wow-delay="0.4s"><?php the_category(, );?></span><spanclass="text-muted wow fadeInUp"data-wow-delay="0.4s"> - <?php the_time(get_option(date_format))?></span><pclass="text-muted d-block mt-3 wow fadeInUp"data-wow-delay="0.6s"><?php echo mb_strimwidth(strip_tags(apply_filters(the_content, $post->post_content)),0,100,);?></p></li><?php endforeach;?><?php endif;?><?php wp_reset_query();?>
(window.slotbydup = window.slotbydup || []).push({ id: "u6835052", container: "_96bek913mdb", async: true });

本文链接:http://blog.sauo.top/?id=538 感谢分享!

分享到:

扫描二维码推送至手机访问。

版权声明:本文由冬眠先生个人博客发布,如需转载请注明出处。

本文链接:http://blog.sauo.top/?id=538

分享给朋友:

“全程干货(wordpress如何添加栏目)wordpress调用指定文章,wordpress如何调用栏目中最新文章,wordpress如何调用栏目中最新文章,” 的相关文章

原创(禁止ping命令操作)linux如何停止ping,linux禁ping操作的方法,linux禁ping操作的方法,

免费领取腾讯云服务器! linux中可以通过ssh命令来禁止其它机器来ping自己,下面是配置方法,大家可以参考一下。 linux中禁ping的方法 方法1 临时禁ping,系统重启后失效,已在ubuntu系...

硬核推荐(ubuntu取消自动休眠)ubuntu关闭自动休眠命令,ubuntu 关闭自动休眠模式的方法,ubuntu 关闭自动休眠模式的方法,

硬核推荐(ubuntu取消自动休眠)ubuntu关闭自动休眠命令,ubuntu 关闭自动休眠模式的方法,ubuntu 关闭自动休眠模式的方法,

免费领取腾讯云服务器! 在使用ssh连接ubuntu系统时,发现长时间不输入ssh命令ssh就会自动断开。查找了一下原因,发现是安装ubuntu的电脑自动进入了休眠模式,而ubuntu系统中有多种关闭自动休眠的方法,下面就来说一说使用ssh命令来关闭ubu...

万万没想到(Ubuntu安装ssh服务)ubuntu配置ssh服务器,ubuntu安装ssh服务器的方法,ubuntu安装ssh服务器的方法,

万万没想到(Ubuntu安装ssh服务)ubuntu配置ssh服务器,ubuntu安装ssh服务器的方法,ubuntu安装ssh服务器的方法,

免费领取腾讯云服务器! 安装了一个ubuntu系统,想着在内网中用ssh进行远程连接管理。下面这篇博文就说说如果在ubuntu系统中安装ssh远程管理服务。 ubuntu 安装ssh服务器的方法 1、安装 openssh-s...

新鲜出炉(ubuntu系统与centos系统区别)ubuntu还是centos,centos系统与ubuntu系统的区分,centos系统与ubuntu系统的区分,

免费领取腾讯云服务器! Linux的发行版有很多,而我们经常使用的为centos与ubuntu,下面这篇博文就说说这两个系统的发源与区别。 CentOS CentOS(Community Enterprise Operati...

干货分享(php file_get_contents curl)php file_get_contents post,php file_get_contents(): SSL operation failed with code 1. OpenSSL Error message.....,php file_get_contents(): SSL operation failed with code 1. OpenSSL Error message.....,

免费领取腾讯云服务器! 在调试php脚本代码时,发现使用 file_get_contents() 函数请求HTTPS的网址链接时出现了报错,其报错代码如下面所示“file_get_contents(): SSL operation failed with...

干货分享(php输出json中文乱码)json数据中文乱码怎么办,解决 php json中文乱码的问题,解决 php json中文乱码的问题,

免费领取腾讯云服务器! php输出使用json_encode函数生成的json数据的时候,发现数据中的中文被转义成了unicode编码,如果使用ajax请求的json数据还好一点,浏览器会自动将unicode编码转义回来,但如果直接输出到浏览器上,那就会直...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。