wordpress 常用函数

来源:互联网 发布:苹果软件商店图标 编辑:程序博客网 时间:2024/06/11 04:16

wp_loginout():主题中显示“登出”链接。


clean_url():入URL并测试它的结构是否正确。如果链接前面缺少http://它可以自动添加,转换符号为正确的HTML。


wpautop() :这个函数用来转换换行符字符串为<br />标记,并把双换行符作为一个新的段落的开始,在前一段加入</p>,并在新的段落加上<p>


显示10篇最新更新文章

<?php get_archives('postbypost', 10); ?>

<?php wp_get_archives('type=postbypost&limit=20&format=custom'); ?>


随机文章

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

显示10条最新留言

<?phpglobal $wpdb;$sql = "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_excerptFROM $wpdb->commentsLEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =$wpdb->posts.ID)WHERE comment_approved = '1' AND comment_type = '' ANDpost_password = ''ORDER BY comment_date_gmt DESCLIMIT 10";$comments = $wpdb->get_results($sql);$output = $pre_HTML;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 .= $post_HTML;echo $output;?>


0 0
原创粉丝点击