当前位置: 首页 > article >正文

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; ?>

  

转载于:https://www.cnblogs.com/qiandu/p/4034847.html

http://www.lryc.cn/news/2419334.html

相关文章:

  • MFC 刷新失效的Picture控件
  • Gensim做中文主题模型(LDA)
  • 利用电脑玩android版天天连萌刷高分 二,利用计算机玩Android版“天天连萌”刷高分(一)——截图...
  • javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative
  • Solid converter【专业PDF转换器】
  • 【爬虫】get 和 post 的区别
  • 如何为微信小程序添加在线客服和用户支持功能
  • Honey Select 2 AIShoujo 自用搜集插件+下载地址
  • svchost.exe[1348]中发生未处理的win32异常 分析
  • 针不错!10+个综合资源网站,好用的很网站!
  • https://www.luogu.org/blog/An-Amazing-Blog/mu-bi-wu-si-fan-yan-ji-ge-ji-miao-di-dong-xi
  • Lou's Pseudo 3d Page v0.91
  • marquee属性详细解答
  • H3C交换机路由器配置命令大全
  • 将数据与OpenLayers结合在一起
  • 图像分割之(五)活动轮廓模型之Snake模型简介
  • shell脚本中四则运算
  • 认识C语言的线程
  • explorer是什么?
  • 一文看懂:网址,URL,域名,IP地址,DNS,2024年最新秀出天际
  • 数据库 超键、候选键、主键、外键
  • 【Flink-HDFS】Call From * to * failed on connection exception: java.net.ConnectException: 拒绝连接;
  • cs服务器(cs索沛服务器)
  • 梯度下降法求解线性回归之python实现
  • ASP.NET运行环境配置
  • 云诺网盘为什么关停了好用的企业网盘有哪些
  • 使用vAPP管理资源
  • Unity - Shader - Projector 高空云层底下透明阴影 - semitransparent shadow
  • Linux 串口RS232/485/GPS 驱动实验(移植minicom)
  • MTK 平台屏蔽 factory mode