• 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 .= "
    <ul>"; 
    		foreach ($comments as $comment) { 
    			$output .= "
    <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 .= "
    </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; ?>
    

      

  • 相关阅读:
    微信“为盲胞读书”项目上线“团体领读”新功能
    神秘代码让iPhone微信闪退的解决方法
    [腾讯首季业绩数据]微信支付用户数持续上升
    [民间调查]小学生微信使用情况的调查 90%小学高年级学生用微信
    O2O模式成功案例分享 汲取精华化为己用
    太原警方通过微博提醒您手机丢失如何保微信安全
    百度富媒体展示允许自定义站点Logo/简介等
    网页出现scanstyles does nothing in Webkit / Mozilla的解决方法
    安卓微信新版内测 可分享小视频/可设微信字体大小
    微信电脑版微信1.1 for Windows更新 可@人/转发撤回消息/可播小视频
  • 原文地址:https://www.cnblogs.com/qiandu/p/4034847.html
Copyright © 2020-2023  润新知