wordpress一些常用代码
显示最新文章
<div id="newpost">
<h2> 最新文章</h2>
<?php
$previous_posts = get_posts('numberposts=15');
foreach($previous_posts as $post) :
setup_postdata($post);
?>
<li>
<a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>">
<?php
the_title();
?>
</a>
</li>
<?php /*?><?php the_content(); ?><?php */?>
<?php endforeach; ?>
</div>
<div id="newcomment">
显示最新评论
<h2>最新评论</h2>
<div id="newcom">
<?php
globa$wpdb;
$sq= "SELECT DISTINCT ID, post_title, post_password, comment_ID,comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 10";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
$output .= "\n<ul>";
foreach ($comments as $comment) {
$output .= "\n<li>".strip_tags($comment->comment_author) .":" . "<a href=\"" . get_permalink($comment->ID). "#comment-" . $comment->comment_ID . "\" title=\"on " . $comment->post_title . "\">" .strip_tags($comment->com_excerpt) ."</a></li>";
}
$output .= "\n</ul>";
$output .= $post_HTML;
echo $output;
?>
</div>
</div>
显示热评文章
<div id="reping">
<h2> 最受关注文章</h2>
<?php
$result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 10");
foreach ($result as $topten) {
$postid = $topten->ID;
$title = $topten->post_title;
$commentcount = $topten->comment_count;
if ($commentcount != 0) { ?>
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?></a></li>
<?php } } ?>
</div>
调用 Gravatar(只适应 2.5以上)
<?php if(function_exists('get_avatar')){ echo get_avatar($comment, '50');} ?>
调用前两篇日志,后续 3篇日志列表
<?php query_posts('showposts=2'); ?><?php if (have_posts()) : while (have_posts()) :
the_post(); ?>
<h2<?php the_title(); ?></h2>
Posted on <?php the_time('F jS, Y') ?> in <?php the_category(', '); ?>
<?php endwhile; endif; ?><!-- google ad script -->
(Google ads here)
<?php query_posts('showposts=3&offset=2'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
Posted on <?php the_time('F jS, Y') ?> in <?php the_category(', '); ?>
<?php endwhile; endif; ?>
随机文章
<div id="rand">
<h2>随机文章</h2>
<?php
$rand_posts = get_posts('numberposts=10&orderby=rand');
foreach( $rand_posts as $post ) : ?>
<!--下面是你想自定义的 Loop-->
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?></div>
安全的调用 Wordpress插件模板代码
<?php if ( function_exists(’plugin_template_tag_function’) ) : ?>
<h2>部件标题</h2>
<?php plugin_template_tag_function(); ?>
<?php endif; ?>
wordpress一些常用代码的更多相关文章
- GCD 常用代码
GCD 常用代码 体验代码 异步执行任务 - (void)gcdDemo1 { // 1. 全局队列 dispatch_queue_t q = dispatch_get_global_queue(0, ...
- 转--Android实用的代码片段 常用代码总结
这篇文章主要介绍了Android实用的代码片段 常用代码总结,需要的朋友可以参考下 1:查看是否有存储卡插入 复制代码 代码如下: String status=Environment.getE ...
- 刀哥多线程之03GCD 常用代码
GCD 常用代码 体验代码 异步执行任务 - (void)gcdDemo1 { // 1. 全局队列 dispatch_queue_t q = dispatch_get_global_queue(0, ...
- jquery常用代码集锦
1. 如何修改jquery默认编码(例如默认GB2312改成 UTF-8 ) 1 2 3 4 5 $.ajaxSetup({ ajaxSettings : { contentT ...
- Mysql:常用代码
C/S: Client Server B/S: Brower Server Php主要实现B/S .net IIS Jave TomCat LAMP:L Mysql:常用代码 Create table ...
- javascript常用代码大全
http://caibaojian.com/288.html 原文链接 jquery选中radio //如果之前有选中的,则把选中radio取消掉 $("#tj_cat .pro_ca ...
- Android 常用代码大集合 [转]
[Android]调用字符串资源的几种方法 字符串资源的定义 文件路径:res/values/strings.xml 字符串资源定义示例: <?xml version="1.0&q ...
- NSIS常用代码整理
原文 NSIS常用代码整理 这是一些常用的NSIS代码,少轻狂特意整理出来,方便大家随时查看使用.不定期更新哦~~~ 1 ;获取操作系统盘符 2 ReadEnvStr $R0 SYSTEMDRIVE ...
- PHP常用代码大全(新手入门必备)
PHP常用代码大全(新手入门必备),都是一些开发中常用的基础.需要的朋友可以参考下. 1.连接MYSQL数据库代码 <?php $connec=mysql_connect("loc ...
随机推荐
- 浅谈localStorage本地存储
在年会的抽奖程序中用到了localStorage现在拿出来总结下,localStorage的相关用法. 在年会抽奖的程序中,需要把获奖名单存储下来,年会现场没有网络,能最简单实现数据存储的方式就是,将 ...
- 检测.net framework 版本
项目中,自己要制作asp.net项目的安装文件,由于项目依赖于.net framework 3.5 sp1,故需检测环境是否符合要求,才能安装程序 度娘找到检测方案:各.net版本对应的安装补录下都有 ...
- LFS,编译自己的Linux系统 - 完成准备工作
$LFS 确保环境变量$LFS已被定义. 定义:export LFS=/mnt/lfs 检查:echo $LFS 建立目录 $LFS/tools $LFS/tools目录用于存放和编译一些临时使用的工 ...
- MySQL用户管理语句001
总的来说mysql的用户管理方法可以分为如下两种: 1.直接对mysql.user 表进行[insert | update | delete] + flush privileges 这种方式主要针对那 ...
- Qt编程可不可以结合其他的第三方库和本土API?(有zeroMQ的Qt封装,还可轻易使用Python的库)
作者:渡世白玉链接:http://www.zhihu.com/question/29030777/answer/59378712来源:知乎著作权归作者所有,转载请联系作者获得授权. 可以,十分可以,你 ...
- C# Struct结构体
C#中结构类型和类类型在语法上非常相似,他们都是一种数据结构,都可以包括数据成员和方法成员. 结构和类的区别: 1.结构是值类型,它在栈中分配空间:而类是引用类型,它在堆中分配空间,栈中保存的只是引用 ...
- UESTC_菲波拉契数制升级版 2015 UESTC Training for Dynamic Programming<Problem L>
L - 菲波拉契数制升级版 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Su ...
- UESTC_In Galgame We Trust CDOJ 10
As we all know, there are many interesting (H) games in kennethsnow’s computer. But he sets a passwo ...
- LeeCode-Linked List Cycle
Given a linked list, determine if it has a cycle in it. /** * Definition for singly-linked list. * s ...
- HTML5 Canvas动画效果演示 - 流浪的鱼 - 博客频道 - CSDN.NET
HTML5 Canvas动画效果演示 - 流浪的鱼 - 博客频道 - CSDN.NET HTML5 Canvas动画效果演示