欢迎光临
我们一直在努力

如何在WordPress网站上调用最新热门文章|同分类随机文章|全站随机调用纯代码教程

如何在WordPress网站上调用最新热门文章、同分类随机文章、随机文章纯代码教程。WordPress网站如何调用最新、热门的张文和指定分类的文章和随机张文纯代码教程。在我们的WordPress主题制作过程中,调用文章的代码应该是使用最频繁的,根据主题功能需求的多样性,调用文章的需求变得繁琐。

wordpress调用全站热门文章代码:

<?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(); ?>"><?php the_title(); ?></a></li>

<?php } wp_reset_query();?>

wordpress调用同分类随机文章代码:

<?php

$cat = get_the_category();

foreach($cat as $key=>$category){

$catid = $category->term_id;}

$args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid ); // 显示篇数

$query_posts = new WP_Query();

$query_posts->query($args);

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

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

<?php endwhile;?>

<?php wp_reset_query(); ?>

 

wordpress调用全站随机文章代码:

<?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(); ?>"><?php the_title(); ?></a></li>

<?php endwhile; ?>

 

WordPress调用指定分类文章:

<?php
    $args=array(
        'cat' => 1,   // 分类ID
        'posts_per_page' => 10, // 显示篇数

    );
    query_posts($args);

    if(have_posts()) : while (have_posts()) : the_post();
?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
    </li>
<?php  endwhile; endif; wp_reset_query(); ?>

 

wordpress调用最新文章

<?php query_posts('showposts=6&cat=-1'); ?>  // 显示篇数和排除分类
<ul>  
<?php while (have_posts()) : the_post(); ?>  
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>  
<?php endwhile;?>  
</ul>  

 

赞(0) 打赏
未经允许不得转载:新起点博客 » 如何在WordPress网站上调用最新热门文章|同分类随机文章|全站随机调用纯代码教程


关注公众号『新起点软件管家』

获取最新网络资源及破解软件!
带你玩转各样软件...

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏