WordPress無插件調用最新、熱門、隨機文章實例代碼
發(fā)布時間:2013-06-05 16:50:08 作者:佚名
我要評論

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>
復制代碼
代碼如下:<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>
相關文章
CyberPanel安裝WordPress并配置偽靜態(tài)規(guī)則
下面教你如何在 CyberPanel安裝WordPress以及配置偽靜態(tài),需要的朋友可以參考下2023-12-27- 這篇文章主要介紹了wordpress無法安裝更新主題插件的解決辦法,需要的朋友可以參考下2020-12-27
- 發(fā)現幾條比較實用的,適合 WordPress 實用的SQL語句。于是就趕緊收集分享出來了,需要的朋友可以參考下2017-09-23
wordpress在安裝使用中出現404、403、500及502問題的分析與解決方法
wordpress是很多新手站長搭建個人博客最喜愛的程序,但是最近在使用WordPress的時候遇到了一些問題,所以想著將遇到問題總結分享出來,下面這篇文章主要給大家介紹了關于wo2017-08-11WordPress取消英文標點符號自動替換中文標點符號的優(yōu)雅方法
這篇文章主要介紹了WordPress取消英文標點符號自動替換中文標點符號的優(yōu)雅方法,需要的朋友可以參考下2017-04-04- 這篇文章主要給大家介紹了wordpress自定義上傳文件類型的方法,如WordPress默認允許上傳 .exe 后綴名的可運行文件,那么我們怎么禁止用戶在WordPress后臺發(fā)表文章時上傳 .e2016-12-19
- 大家可能發(fā)現了當實現了前端用戶中心,后臺控制面板就失去了作用,那么限制其他用戶進入后臺控制面板就很有必要了!那么我們要怎么做呢?通過下面這篇文章分享的方法后,只2016-12-19
WordPress實現回復文章評論后發(fā)送郵件通知的功能
這篇文章主要介紹了WordPress實現回復文章評論后發(fā)送郵件通知的功能,涉及wordpress針對評論與郵件的相關操作技巧,需要的朋友可以參考下2016-10-11- 這篇文章主要介紹了WordPress使用自定義文章類型實現任意模板的方法,可通過自定義文章類型來實現任意模版的使用,具有一定參考借鑒價值,需要的朋友可以參考下2016-10-11
WordPress后臺地址被改導致無法登陸后臺的簡單解決方法
這篇文章主要介紹了WordPress后臺地址被改導致無法登陸后臺的簡單解決方法,簡單分析了后臺無法登陸的原因與相應的解決方法,涉及針對wordpress配置項的簡單修改,需要的朋友2016-10-11