wordpress主题设计中如何调用最新热门随机文章
发布时间:2022-06-26 15:36:38 所属栏目:教程 来源:互联网
导读:如果想在wordpress主题制作过程中调用最新、热门、随机文章,可以使用wordpress自带的widget侧边栏的小工具功能来实现,但是这样会影响到我们想自定义侧边栏的效果,当然也有一些可以使用插件来实现这个功能的,不过使用插件始终对SEO方面有一定的影响,下面我
如果想在wordpress主题制作过程中调用最新、热门、随机文章,可以使用wordpress自带的widget侧边栏的小工具功能来实现,但是这样会影响到我们想自定义侧边栏的效果,当然也有一些可以使用插件来实现这个功能的,不过使用插件始终对SEO方面有一定的影响,下面我给大家介绍一种不用插件也能实现. wordpress最新、热门、随机文章的调用方法. 1、最新文章的调用代码: <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> 2、热门文章的调用代码: <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 //开源软件:phpfensi.com (); ?></a></li> <?php } wp_reset_query();?> </ul> 3、随机文章的调用代码: <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> 从上三种文章的代码调用方法都测试过,其中最新文章和随机文章的调用方法是没有问题的,而热门文章的调用代码不知道为什么不能正常显示,但是删除了post_password’ => ”,这句代码就可以正常调用,不知道有没有那位大神可以留言告诉我原因,还有热门文章的调用,如果想依浏览数来排序又是怎么实现的呢?期高手的出现. (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐