调用同分类下的随机文章

<ul>
    <?php
    $cat = get_the_category();
    foreach($cat as $key=>$category){
        $catid = $category->term_id;
    }
    $args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid );
    $query_posts = new WP_Query();
    $query_posts->query($args);
    while ($query_posts->have_posts()) : $query_posts->the_post();
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile;?>
    <?php wp_reset_query(); ?>
</ul>

增加回复可见功能

//加入回复可见功能
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '<p class="reply-to-read">温馨提示: 此处内容需要<a href="#respond" title="评论本文">评论本文</a>后才能查看.</p>'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
//对博主直接显示内容
$admin_email = "homgmail@foxmail.com"; //博主Email
if ($email == $admin_email) {
return $content;
}
} else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
} else {
return $notice;
}
if (empty($email)) {
return $notice;
}
global $wpdb;
$post_id = get_the_ID();
$query = "SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID={$post_id} and comment_approved='1' and comment_author_email='{$email}' LIMIT 1"; if ($wpdb->get_results($query)) { return do_shortcode($content); } else { return $notice; } } add_shortcode('reply', 'reply_to_read'); //对博主直接显示内容结束

写文章用 reply 包裹。

增加百度主动提交功能

functions:

if(!function_exists('Baidu_Submit')){
 function Baidu_Submit($post_ID) {
 $WEB_TOKEN = 'xxxxxxxxxxx'; //这里请换成你的网站的百度主动推送的token值
 $WEB_DOMAIN = get_option('home');
 //已成功推送的文章不再推送
 if(get_post_meta($post_ID,'Baidusubmit',true) == 1) return;
 $url = get_permalink($post_ID);
 $api = 'http://data.zz.baidu.com/urls?site='.$WEB_DOMAIN.'&token='.$WEB_TOKEN;
 $request = new WP_Http;
 $result = $request->request( $api , array( 'method' => 'POST', 'body' => $url , 'headers' => 'Content-Type: text/plain') );
 $result = json_decode($result['body'],true);
 //如果推送成功则在文章新增自定义栏目Baidusubmit,值为1
 if (array_key_exists('success',$result)) {
 add_post_meta($post_ID, 'Baidusubmit', 1, true);
 }
 }
 add_action('publish_post', 'Baidu_Submit', 0);
}

相关文章:

<h3>您可能感兴趣的文章</h3>
            <div class="related_posts">
            <?php
            $post_num = 12;
            $exclude_id = $post->ID;
            $posttags = get_the_tags(); $i = 0;
            if ( $posttags ) {
                $tags = ''; foreach ( $posttags as $tag ) $tags .= $tag->term_id . ',';
                $args = array(
                    'post_status' => 'publish',
                    'tag__in' => explode(',', $tags),
                    'post__not_in' => explode(',', $exclude_id),
                    'caller_get_posts' => 1,
                    'orderby' => 'comment_date',
                    'posts_per_page' => $post_num,
                );
                query_posts($args);
                while( have_posts() ) { the_post(); ?>
                    <li><a rel="bookmark" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></li>
                <?php
                    $exclude_id .= ',' . $post->ID; $i ++;
                } wp_reset_query();
            }
            if ( $i < $post_num ) {
                $cats = ''; foreach ( get_the_category() as $cat ) $cats .= $cat->cat_ID . ',';
                $args = array(
                    'category__in' => explode(',', $cats),
                    'post__not_in' => explode(',', $exclude_id),
                    'caller_get_posts' => 1,
                    'orderby' => 'comment_date',
                    'posts_per_page' => $post_num - $i
                );
                query_posts($args);
                while( have_posts() ) { the_post(); ?>
                    <li><a rel="bookmark" href="<?php the_permalink(); ?>"  title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></li>
                <?php $i++;
                } wp_reset_query();
            }
            if ( $i  == 0 )  echo '<li>没有相关文章!</li>';
            ?>
            </div>

评论回复对方

// 评论回应邮件通知
function comment_mail_notifydemo($comment_id) {
$admin_notify = '1'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 )
$admin_email = get_bloginfo ('admin_email'); // $admin_email 可改为你指定的 e-mail.
$comment = get_comment($comment_id);
$comment_author_email = trim($comment->comment_author_email);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
global$wpdb;
if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notifydemo") == '')
$wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notifydemo TINYINT NOT NULL DEFAULT 0;");
if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notifydemo'])) || ($comment_author_email == $admin_email && $admin_notify == '1'))
$wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notifydemo='1' WHERE comment_ID='$comment_id'");
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notifydemo : '0';
$spam_confirmed = $comment->comment_approved;
if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') {
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 发出点, no-reply 可改为可用的 e-mail.
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = '您在 [' . get_option("blogname") . '] 的留言有了回应';
$message = '
<div style="background-color:#eef2fa; border:1px solid #d8e3e8; color:#111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px;">
<p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p>
<p>您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:<br />'
. trim(get_comment($parent_id)->comment_content) . '</p>
<p>' . trim($comment->comment_author) . ' 给您的回应:<br />'
. trim($comment->comment_content) . '<br /></p>
<p>您可以点击 <a href="' . htmlspecialchars(get_comment_link($parent_id)) . '">查看回应完整內容</a></p>
<p>欢迎您再度光临 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p>
<p>(此邮件由系统自动发出,请勿回复.)</p>
</div>';
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail( $to, $subject, $message, $headers );
//echo 'mail to ', $to, '<br/> ' , $subject, $message; // for testing
}
}
add_action('comment_post', 'comment_mail_notifydemo');
// 自动勾选
function add_checkbox() {
echo '<input type="checkbox" name="comment_mail_notifydemo" id="comment_mail_notifydemo" value="comment_mail_notifydemo" checked="checked" style="margin-left:0px;" /><label for="comment_mail_notifydemo">有人回复时邮件通知我</label>';
}
add_action('comment_form', 'add_checkbox');

给图片自动添加alt属性

//给文章图片自动添加alt和title信息
add_filter('the_content', 'imagesalt');
function imagesalt($content) {
       global $post;
       $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
       $replacement = '<a$1href=$2$3.$4$5 alt="'.$post->post_title.'" title="'.$post->post_title.'"$6>';
       $content = preg_replace($pattern, $replacement, $content);
       return $content;
}

给图片自动链接本身

function auto_img_link($content)
{
global $post;
$content = preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', "<a href=\"$2\" title=\"".$post->post_title."\" ><img src=\"$2\" alt=\"".$post->post_title."\" /></a>", $content);
return $content;
}
add_filter ('the_content', 'auto_img_link',0);

您可能感兴趣的文章


一个爱好捣鼓网站的男孩纸!