iis服务器助手广告广告
返回顶部
首页 > 资讯 > CMS >WordPress无插件调用最新、热门、随机文章实例代码
  • 760
分享到

WordPress无插件调用最新、热门、随机文章实例代码

最新文章热门文章随机文章 2022-06-12 02:06:18 760人浏览 薄情痞子
摘要

调用最新文章: 复制代码代码如下: <ul> <?PHP $post_query = new WP_Query(‘showposts=10′); while ($post_que

调用最新文章:


复制代码代码如下:

<ul>

<?PHP $post_query = new WP_Query(‘showposts=10′);

while ($post_query->have_posts()) : $post_query->the_post();

$do_not_duplicate = $post->ID; ?>

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

<?php endwhile;?>

</ul>

调用热门文章:


复制代码代码如下:

<ul>

<?php

$post_num = 10; // 设置调用条数

$args = array(

‘post_passWord’ => ”,

‘post_status’ => ‘publish’, // 只选公开的文章.

‘post__not_in’ => array($post->ID),//排除当前文章

‘caller_get_posts’ => 1, // 排除置顶文章.

‘orderby’ => ‘comment_count’, // 依评论数排序.

‘posts_per_page’ => $post_num

);

$query_posts = new WP_Query();

$query_posts->query($args);

while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>

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

<?php } wp_reset_query();?>

</ul>

调用随机文章:


复制代码代码如下:

<ul>

<?php

global $post;

$postid = $post->ID;

$args = array( ‘orderby’ => ‘rand’, ‘post__not_in’ => array($post->ID), ‘showposts’ => 10);

$query_posts = new WP_Query();

$query_posts->query($args);

?>

<?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?>

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

<?php endwhile; ?>

</ul>

--结束END--

本文标题: WordPress无插件调用最新、热门、随机文章实例代码

本文链接: https://www.lsjlt.com/news/32132.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作