WordPress文章相关代码记录

1.最新评论带头像缓存

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
29
30
<h3><?php _e('Recent Comments'); ?></h3>
<ul class="recentcomments">
<?php
global $wpdb;
$my_email = get_bloginfo ('admin_email');
$rc_comms = $wpdb->get_results("
  SELECT ID, post_title, comment_ID, comment_author, comment_author_email, comment_content
  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 = ''
  AND comment_author_email != '$my_email'
  ORDER BY comment_date_gmt
  DESC LIMIT 10
"
);
$rc_comments = '';
foreach ($rc_comms as $rc_comm) {
  $a = 'avatar/'.md5(strtolower($rc_comm->comment_author_email)).'.jpg'; // 頭像緩存用的
  $rc_comments .= "<li><img src='" . $a . "' alt='' title='" . $rc_comm-/>comment_author
    . "' class='avatar' /><a href='"
    . get_permalink($rc_comm->ID) . "#comment-" . $rc_comm->comment_ID
  //. htmlspecialchars(get_comment_link( $rc_comm->comment_ID, array('type' => 'comment'))) // 可取代上一行, 會顯示 cpage, 但較耗資源
    . "' title='on " . $rc_comm->post_title . "'>" . strip_tags($rc_comm->comment_content)
    . "</a></li>\n";
}
$rc_comments = convert_smilies($rc_comments);
echo $rc_comments;
?>
</ul>

2.月度文章下拉框显示

1
2
3
4
<select name=\"archive-dropdown\" onChange='document.location.href=this.options[this.selectedIndex].value;'>
    <option value=\"\"><?php echo attribute_escape(__('Select Month')); ?></option>
    <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?>
</select>

发表评论