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 ...
随机推荐
- FastJSON 简单使用
FastJSON是一个Java语言编写的高性能,功能完善,完全支持http://json.org的标准的JSON库.多了不说了,百度一下一大把. 在此,简单的总结一下自己用过,测试过的方法. 如果使用 ...
- 我的第一个comet长连接例子
<!doctype html> <html> <head> <meta charset="utf-8"> <meta http ...
- C语言基本概念
1. 标准C语言 C语言诞生于20世纪70年代,年龄比我们自己还要大,期间产生了很多标准,但是各种编译器对标准的支持不尽相同. ANSI C是使用的最广泛的一个标准,也是第一个正式标准,被称为“标准C ...
- ccf练习---节日
问题描述 有一类节日的日期并不是固定的,而是以“a月的第b个星期c”的形式定下来的,比如说母亲节就定为每年的五月的第二个星期日. 现在,给你a,b,c和y1, y2(1850 ≤ y1, y2 ≤ 2 ...
- WPF笔记(1.6 数据绑定)——Hello,WPF!
原文:WPF笔记(1.6 数据绑定)--Hello,WPF! 这个一节都是在讲一个数据绑定的示例.功用:输入姓和名,点击Add按钮,ListBox增加一条记录,永远是字符串“name: nick”:L ...
- 【Xamarin挖墙脚系列:开始使用Xamari4.0系列产品开发IOS】
一直沉默在Xamarin3.0系列版本上,升级到4.0之后,感觉有些变化.还得适应下. 1 build.host 代理消失了,成了SSH客户端登录.所以,Mac设备需要打开运行远程登录. 2 在Wi ...
- 数据类型MSVC和gcc/g++的不同
前言: 在16位环境下,int/unsigned int 占16位,long/unsigned long占32位 在32位环境下,int占32位,unsigned int占16位,long/unsig ...
- 开源欣赏wordpress之用户新增user-new.php
require_once( dirname( __FILE__ ) . '/admin.php' ); 引入根文件. if ( is_multisite() ) { if ( ! current_us ...
- 括号匹配问题(C++、堆栈)
原文地址:http://www.cppblog.com/GUO/archive/2010/09/12/126483.html /* 括号匹配问题,比较经典,利用堆栈来实现(摘自internet) 1. ...
- Binary Search Tree Iterator 解答
Question Implement an iterator over a binary search tree (BST). Your iterator will be initialized wi ...