排除 wordpress 最新文章列表中的置顶文章

前端之家收集整理的这篇文章主要介绍了排除 wordpress 最新文章列表中的置顶文章前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在使用的过程中,我们有时希望把最新文章列表和置顶文章列表分开输出显示。可是当我们调用最新文章列表的时候,如果 wordpress网站中有置顶文章的话,那么最新文章列表中会把里面的置顶文章显示出来,而且在最前面。我们如何让才能排除最新文章列表中的置顶文章呢?下面我们来介绍一下方法,原理是通过设置置顶文章的参数caller_get_posts来实现。

切换到主题目录,在需要调用的地方插入如下代码,即可实现:

Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d3097c99975337342-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3097c99975337342-2">2
Crayon-num" data-line="Crayon-5c891d3097c99975337342-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3097c99975337342-4">4
Crayon-num" data-line="Crayon-5c891d3097c99975337342-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3097c99975337342-6">6
Crayon-num" data-line="Crayon-5c891d3097c99975337342-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3097c99975337342-8">8
Crayon-num" data-line="Crayon-5c891d3097c99975337342-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3097c99975337342-10">10
Crayon-num" data-line="Crayon-5c891d3097c99975337342-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3097c99975337342-12">12
Crayon-num" data-line="Crayon-5c891d3097c99975337342-13">13
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d3097c99975337342-14">14
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d3097c99975337342-1">Crayon-ta">PHP
Crayon-line Crayon-striped-line" id="Crayon-5c891d3097c99975337342-2">Crayon-h">Crayon-v">$post_numCrayon-h"> Crayon-o">=Crayon-h"> Crayon-cn">10Crayon-sy">;Crayon-h"> Crayon-c">// 显示文章数量
Crayon-line" id="Crayon-5c891d3097c99975337342-3">Crayon-h">Crayon-v">$argsCrayon-o">=Crayon-t">arrayCrayon-sy">(
Crayon-line Crayon-striped-line" id="Crayon-5c891d3097c99975337342-4">Crayon-h">Crayon-s">'post_status'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'publish'Crayon-sy">,
Crayon-line" id="Crayon-5c891d3097c99975337342-5">Crayon-h">Crayon-s">'paged'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-v">$pagedCrayon-sy">,
Crayon-line Crayon-striped-line" id="Crayon-5c891d3097c99975337342-6">Crayon-h">Crayon-s">'caller_get_posts'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-cn">1Crayon-sy">,
Crayon-line" id="Crayon-5c891d3097c99975337342-7">Crayon-h">Crayon-s">'posts_per_page'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-v">$post_num
Crayon-line Crayon-striped-line" id="Crayon-5c891d3097c99975337342-8">Crayon-h">Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d3097c99975337342-9">Crayon-h">Crayon-e">query_postsCrayon-sy">(Crayon-v">$argsCrayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d3097c99975337342-10">Crayon-h">Crayon-c">// 主循环
Crayon-line" id="Crayon-5c891d3097c99975337342-11">Crayon-h">Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">have_postsCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-o">:Crayon-h"> Crayon-st">whileCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-e">have_postsCrayon-sy">(Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-o">:Crayon-h"> Crayon-e">the_postCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d3097c99975337342-12">
Crayon-line" id="Crayon-5c891d3097c99975337342-13">Crayon-o"><Crayon-v">liCrayon-o"><Crayon-i">aCrayon-h"> Crayon-v">hrefCrayon-o">=Crayon-s">"Crayon-ta">PHPCrayon-h"> Crayon-e">the_permalinkCrayon-sy">(Crayon-sy">)Crayon-h"> "Crayon-ta">PHPCrayon-h"> Crayon-e">the_titleCrayon-sy">(Crayon-sy">)Crayon-sy">;Crayon-h"> Crayon-o"><Crayon-o">/Crayon-e">aCrayon-o"><Crayon-o">/Crayon-e">li
Crayon-line Crayon-striped-line" id="Crayon-5c891d3097c99975337342-14">Crayon-ta">PHPCrayon-h"> Crayon-st">endwhileCrayon-sy">;Crayon-h"> Crayon-st">elseCrayon-o">:Crayon-h"> Crayon-st">endifCrayon-sy">;Crayon-h"> Crayon-e">wp_reset_queryCrayon-sy">(Crayon-sy">)Crayon-sy">;

猜你在找的wordpress相关文章