手机
当前位置:查字典教程网 >CMS教程 >WordPress >WordPress无插件调用最新、热门、随机文章实例代码
WordPress无插件调用最新、热门、随机文章实例代码
摘要:调用最新文章:调用热门文章:”>调用随机文章:”>

调用最新文章:

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

【WordPress无插件调用最新、热门、随机文章实例代码】相关文章:

在wordpress可视化编辑器中输入带缩进的代码

wp-Syntax wordpress高亮插件使用方法

wordpress获取文章评论数过滤掉作者代码分享

wordpress博客搜索关键词高亮显示实现代码

WordPress源代码中文乱码的解决方法

WordPress 文章摘要功能实现代码

wordpress固定链接翻译插件 自动将标题翻译成英文

WordPress 链接跳转插件

wordpress利用键盘左右键实现上下翻页的方法

wordpress恶意代码解决方法分享

精品推荐
分类导航