WordPress实现文章内容有更新提示附美化样式|纯代码

网站经常有些老文章更新,但是却没有提示,导致用户不知道或者需要重新置顶文章,这里给wordpress添加一个显示最近更新过文章的调用方法。

wordpress调用最近更新文章列表
1、将以下代码添加到主题的 functions.php里

function recently_updated_posts(num=10,num=10,days=7) {
if( !$recently_updated_posts = get_option(‘recently_updated_posts’) ) {
query_posts(‘post_status=publish&orderby=modified&posts_per_page=-1’);
$i=0;
while ( have_posts() && i<i<num ) : the_post();
if (current_time(‘timestamp’) - get_the_time(‘U’) > 606024*$days) {
$i++;
$the_title_value=get_the_title();
recentlyupdatedposts.=<li><ahref=".getpermalink()."title=".recently_updated_posts.='<li><a href="'.get_permalink().'" title="'.the_title_value.’">’
.KaTeX parse error: Expected 'EOF', got '&' at position 53: …atetime"><br />&̲raquo; 修改时间: ' …recently_updated_posts) ) update_option(‘recently_updated_posts’, $recently_updated_posts);
}
recentlyupdatedposts=(recently_updated_posts=(recently_updated_posts == ‘’) ? ‘

  • None data.
  • ’ : $recently_updated_posts;
    echo $recently_updated_posts;
    }

    function clear_cache_zww() {
    update_option(‘recently_updated_posts’, ‘’); // 清空 recently_updated_posts
    }
    add_action(‘save_post’, ‘clear_cache_zww’); // 新发表文章/修改文章时触发更新
    2、调用方法
    以下代码中 8 为展示文章数量,15 指15天内发表的文章除外,具体使用的时候可以根据自己的情况修改这两个参数。

    Recently Updated Posts

      <?php if ( function_exists('recently_updated_posts') ) recently_updated_posts(8,15); ?>
    提示 作者有添加数据库缓存方式,所以在修改文章/删除文章/发表文章时才会更新缓存。 相关参数说明:$num – 展示数量,$days – 几天内的新文章除外。

    可以将调用代码放在边侧栏或者文章页面任何地方调用。

    效果如下:WordPress实现文章内容有更新提示附美化样式|纯代码wordpress邮件通知评论用户文章更新
    将以下代码添加到functions.php中,会在修改编辑文章的页面添加一个选项,只有勾选才会邮件通知。

    //修改更新文章时邮件通知评论用户
    add_action( ‘submitpost_box’, ‘lxtx_fo_submit_box’);
    function lxtx_fo_submit_box( ){
    echo ‘

    ’;
    echo ‘
    ’;
    echo ‘

    ’;
    echo ‘

    邮件通知

    ’;
    echo ‘
    ’;
    echo ’
    ’;
    echo ‘
    ’;
    echo ‘
    ’;
    echo ‘
    ’;
    }
    //开始
    add_action( ‘publish_post’, ‘lxtx_fo_emaill_report_users’ );
    function lxtx_fo_emaill_report_users(KaTeX parse error: Expected '}', got 'EOF' at end of input: …存,不进行任何操作 if(_POST[‘FO_emaill_report_user’] != ‘true’){
    return;
    }

    //修订版本不通知,以免滥用
    if( wp_is_post_revision($post_ID) ){
    return;
    }

    //获取wp数据操作类
    global wpdb,wpdb,post;
    // 读数据库,获取文章的所有用户的email并且不重复
    $emailauthor != ‘你自己的邮箱’;
    $wp_user_emails = $wpdb->get_results(“SELECT DISTINCT comment_author, comment_author_email FROM wpdb>commentsWHERETRIM(commentauthoremail)ISNOTNULLANDTRIM(commentauthoremail)!=ANDTRIM(commentauthoremail)!=wpdb->comments WHERE TRIM(comment_author_email) IS NOT NULL AND TRIM(comment_author_email) != '' AND TRIM(comment_author_email) != 'emailauthor’ AND comment_post_ID = $post->ID”);

    // 获取博客名称
    $blogname = wp_specialchars_decode(get_option(‘blogname’), ENT_QUOTES);
    // 获取博客URL
    $blogurl = get_bloginfo(“siteurl”);

    //文章链接
    postlink=getpermalink(post_link = get_permalink(post_ID);
    //文章标题$post -> post_title
    posttitle=striptags(post_title = strip_tags(_POST[‘post_title’]);
    //文章内容$post->post_content
    postcontent=striptags(post_content = strip_tags(_POST[‘post_content’]);
    //文章摘要
    KaTeX parse error: Undefined control sequence: \x at position 30: …replace('/^(?:[\̲x̲00-\x7F]|[\xC0-…post_content).’…’;

    //邮件头,以免乱码
    $message_headers = “Content-Type: text/html; charset=“utf-8”\n”;
    // 邮件标题
    subject=访.subject = '您曾经来访过的《'.post_title.’》文章更新通知。’;

    foreach ( $wp_user_emails as $wp_user_email )
    {
    // 邮件内容
    $message = ’

    亲爱的'.$wp_user_email->comment_author.':

    您曾经来访过的《'.$post_title.'》有更新,博主觉得有必要通知您,希望不会骚扰到您。

    文章标题:'.$post_title.'
    文章摘要:'.$output.'

    您可以点击链接 '.$blogname.' > '.$post_title.' 详细查看

    来自: '.$blogname.'

    该邮件为系统发送邮件,请勿直接回复!如有打扰,请向博主留言反映。灰常感谢您的阅读!
    '; wp_mail($wp_user_email->comment_author_email, $subject, $message, $message_headers); } } ![在这里插入图片描述](https://img-blog.****img.cn/20200102133746622.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3R3MTk5ODA0,size_16,color_FFFFFF,t_70) 本文来自[资源网](https://www.top1sh.com)