汇编大量WordPress代码
显示最新文章
1 2 3 4 5 6 7 8 |
<ol class="dp-c"> <li class="alt"><span><span><?php query_posts(</span><span class="string">’showposts=5′</span><span>); ?> </span></span></li> <li><span><ul> </span></li> <li class="alt"><span><?php <span class="keyword">while</span><span> (have_posts()) : the_post(); ?> </span></span></li> <li><span><li><a href=<span class="string">"<?php the_permalink() ?>"</span><span>><?php the_title(); ?></a></li> </span></span></li> <li class="alt"><span><?php <span class="keyword">endwhile</span><span>;?> </span></span></li> <li><span></ul> </span></li> </ol> |
显示最新评论
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<ol class="dp-c"> <li class="alt"><span><span><?php </span></span></li> <li><span><span class="keyword">global</span><span> </span><span class="vars">$wpdb</span><span>; </span></span></li> <li class="alt"><span><span class="vars">$sql</span><span> = "SELECT DISTINCT ID, post_title, post_password, comment_ID, </span></span></li> <li><span>comment_post_ID, comment_author, comment_date_gmt, comment_approved, </span></li> <li class="alt"><span>comment_type,comment_author_url, </span></li> <li><span>SUBSTRING(comment_content,1,30) AS com_excerpt </span></li> <li class="alt"><span>FROM <span class="vars">$wpdb</span><span>->comments </span></span></li> <li><span>LEFT OUTER JOIN <span class="vars">$wpdb</span><span>->posts ON (</span><span class="vars">$wpdb</span><span>->comments.comment_post_ID = </span></span></li> <li class="alt"><span><span class="vars">$wpdb</span><span>->posts.ID) </span></span></li> <li><span>WHERE comment_approved = <span class="string">‘1′</span><span> AND comment_type = </span><span class="string">”</span><span> AND </span></span></li> <li class="alt"><span>post_password = <span class="string">”</span><span> </span></span></li> <li><span>ORDER BY comment_date_gmt DESC </span></li> <li class="alt"><span>LIMIT 10"; </span></li> <li><span><span class="vars">$comments</span><span> = </span><span class="vars">$wpdb</span><span>->get_results(</span><span class="vars">$sql</span><span>); </span></span></li> <li class="alt"><span><span class="vars">$output</span><span> = </span><span class="vars">$pre_HTML</span><span>; </span></span></li> <li><span><span class="vars">$output</span><span> .= </span><span class="string">"n<ul>"</span><span>; </span></span></li> <li class="alt"><span><span class="keyword">foreach</span><span> (</span><span class="vars">$comments</span><span> </span><span class="keyword">as</span><span> </span><span class="vars">$comment</span><span>) { </span></span></li> <li><span><span class="vars">$output</span><span> .= </span><span class="string">"n<li>"</span><span>.</span><span class="func">strip_tags</span><span>(</span><span class="vars">$comment</span><span>->comment_author) </span></span></li> <li class="alt"><span>.<span class="string">":"</span><span> . </span><span class="string">"<a href=""</span><span> . get_permalink(</span><span class="vars">$comment</span><span>->ID) . </span></span></li> <li><span><span class="string">"#comment-"</span><span> . </span><span class="vars">$comment</span><span>->comment_ID . </span><span class="string">"" title="on "</span><span> . </span></span></li> <li class="alt"><span><span class="vars">$comment</span><span>->post_title . </span><span class="string">"">"</span><span> . </span><span class="func">strip_tags</span><span>(</span><span class="vars">$comment</span><span>->com_excerpt) </span></span></li> <li><span>.<span class="string">"</a></li>"</span><span>; </span></span></li> <li class="alt"><span>} </span></li> <li><span><span class="vars">$output</span><span> .= </span><span class="string">"n</ul>"</span><span>; </span></span></li> <li class="alt"><span><span class="vars">$output</span><span> .= </span><span class="vars">$post_HTML</span><span>; </span></span></li> <li><span><span class="func">echo</span><span> </span><span class="vars">$output</span><span>;?> </span></span></li> </ol> |
显示热评文章
1 2 3 4 5 6 7 8 9 10 |
<ol class="dp-c"> <li class="alt"><span><span><?php </span><span class="vars">$result</span><span> = </span><span class="vars">$wpdb</span><span>->get_results(</span><span class="string">"SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 10"</span><span>); </span></span></li> <li><span><span class="keyword">foreach</span><span> (</span><span class="vars">$result</span><span> </span><span class="keyword">as</span><span> </span><span class="vars">$topten</span><span>) { </span></span></li> <li class="alt"><span><span class="vars">$postid</span><span> = </span><span class="vars">$topten</span><span>->ID; </span></span></li> <li><span><span class="vars">$title</span><span> = </span><span class="vars">$topten</span><span>->post_title; </span></span></li> <li class="alt"><span><span class="vars">$commentcount</span><span> = </span><span class="vars">$topten</span><span>->comment_count; </span></span></li> <li><span><span class="keyword">if</span><span> (</span><span class="vars">$commentcount</span><span> != 0) { ?> </span></span></li> <li class="alt"><span><li><a href=<span class="string">"<?php echo get_permalink($postid); ?>"</span><span> </span></span><span><span>title=</span><span class="string">"<?php echo $title ?>"</span><span>><?php </span><span class="func">echo</span><span> </span><span class="vars">$title</span><span> ?></a></li> </span></span></li> <li><span><?php } } ?> </span></li> </ol> |
显示文章分类
1 2 3 4 5 6 |
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><span class="tag-name">h2</span><span class="tag">></span><span>Categories</span><span class="tag"></</span><span class="tag-name">h2</span><span class="tag">></span><span> </span></span></li> <li><span><span class="tag"><</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li> <li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span> wp_list_cats(’</span><span class="attribute">sort_column</span><span>=</span><span class="attribute-value">name</span><span>‘); </span><span class="tag">?></span><span> </span></span></li> <li><span><span class="tag"></</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li> </ol> |
显示归档
1 2 3 4 5 6 |
<ol class="dp-c"> <li class="alt"><span><span><h2>Archives</h2> </span></span></li> <li><span><ul> </span></li> <li class="alt"><span><?php wp_get_archives(<span class="string">‘type=monthly’</span><span>); ?> </span></span></li> <li><span></ul> </span></li> </ol> |
在侧栏显示页面列表
1 2 3 4 5 6 |
<ol class="dp-c"> <li class="alt"><span><span><h2>Pages</h2> </span></span></li> <li><span><ul> </span></li> <li class="alt"><span><?php wp_list_pages(<span class="string">‘title_li=’</span><span>); ?> </span></span></li> <li><span></ul> </span></li> </ol> |
调用Gravatar(只适应2.5以上)
- <br />
1 2 3 |
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span> if(function_exists(’get_avatar’)){ echo get_avatar($comment, ‘50?);} </span><span class="tag">?></span><span> </span></span></li> </ol> |
显示友情链接
1 2 3 4 5 |
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li> <li><span><span class="tag"><?</span><span class="tag-name">php</span><span> get_links_list(); </span><span class="tag">?></span><span> </span></span></li> <li class="alt"><span><span class="tag"></</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li> </ol> |
显示管理员链接
1 2 3 4 5 6 7 8 9 |
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li> <li><span><span class="tag"><?</span><span class="tag-name">php</span><span> wp_register(); </span><span class="tag">?></span><span> </span></span></li> <li class="alt"><span><span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span class="tag"><?</span><span class="tag-name">php</span><span> wp_loginout(); </span><span class="tag">?></span><span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li> <li><span><span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=</span><span class="attribute-value">"http://www.wordpress.org/"</span><span class="tag">></span><span>WordPress</span><span class="tag"></</span><span class="tag-name">a</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li> <li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span> wp_meta(); </span><span class="tag">?></span><span> </span></span></li> <li><span><span class="tag"><</span><span class="tag-name">li</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=</span><span class="attribute-value">"http://validator.w3.org/check?uri=referer"</span><span class="tag">></span><span>XHTML</span><span class="tag"></</span><span class="tag-name">a</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">li</span><span class="tag">></span><span> </span></span></li> <li class="alt"><span><span class="tag"></</span><span class="tag-name">ul</span><span class="tag">></span><span> </span></span></li> </ol> |
在侧栏显示页面的子页面
1 2 3 4 5 6 |
<ol class="dp-c"> <li class="alt"><span><span><?php</span><span class="vars">$children</span><span> = wp_list_pages(</span><span class="string">‘title_li=&child_of=’</span><span>.</span><span class="vars">$post</span><span>->ID.</span><span class="string">‘&echo=0′</span><span>);</span></span></li> <li class="alt"><span><span class="keyword">if</span><span> (</span><span class="vars">$children</span><span>) { ?><ul> <?php </span><span class="func">echo</span><span> </span><span class="vars">$children</span><span>; ?> </span></span></li> <li><span></ul> </span></li> <li class="alt"><span><?php } ?> </span></li> </ol> |
显示Wordpress标签
- <br />
1 2 3 |
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span> the_tags(); </span><span class="tag">?></span><span> </span></span></li> </ol> |
显示Wordpress标签云
1 2 3 |
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span> wp_tag_cloud(’</span><span class="attribute">smallest</span><span>=</span><span class="attribute-value">8</span><span>&</span><span class="attribute">largest</span><span>=</span><span class="attribute-value">36</span><span>&’); </span><span class="tag">?></span><span> </span></span></li> </ol> |
模板标题
- <br />
1 2 3 |
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span> /* Template Name: Portfolio */ </span><span class="tag">?></span><span> </span></span></li> </ol> |
动态标题标签
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><span class="tag-name">title</span><span class="tag">></span><span class="tag"><?</span><span class="tag-name">phpif</span><span> (is_home()) { echo bloginfo(’name’); </span></span></li> <li><span>} elseif (is_404()) { </span></li> <li class="alt"><span>echo ’404 Not Found’; </span></li> <li><span>} elseif (is_category()) { </span></li> <li class="alt"><span>echo ’Category:’; wp_title(”); </span></li> <li><span>} elseif (is_search()) { </span></li> <li class="alt"><span>echo ’Search Results’; </span></li> <li><span>} elseif ( is_day() || is_month() || is_year() ) { </span></li> <li class="alt"><span>echo ’Archives:’; wp_title(”); </span></li> <li><span>} else { </span></li> <li class="alt"><span>echo wp_title(”); </span></li> <li><span>} </span></li> <li class="alt"><span><span class="tag">?></span><span class="tag"></</span><span class="tag-name">title</span><span class="tag">></span><span> </span></span> ++CoolCode_BLOCK_5++</li> </ol> |
在独立页面中运行PHP
1 2 3 |
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><?</span><span class="tag-name">php</span><span> if ( is_home() ) { include (’file.php’); } </span><span class="tag">?></span><span> </span></span></li> </ol> |
坐等大佬D盘更新,祝大佬全家福寿安康
有公众号之类的吗,之前这个网站打不开了
[…] 关于使用Change…
[…] 关于使用Functi…
谢谢提醒,已删 :)