IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    begin主题二次开发:新增留言版页面模板

    yumanutong发表于 2015-12-19 15:39:19
    love 0

    前段时间,买了这个魔板。也由于忙,今天才上线,小小的折腾修改了下。

    首先,页面模板的文件路径在:/wp-content/themes/begin/pages/

    代码我写好了,你们复制,新建一个php文件即可。如:template-leaveword.php

    然后把下面代码放进去:

    Code   + expand sourceViewPrint
    1. <?php
    2. /*
    3. Template Name: 留言板
    4. */
    5. ?>
    6. <?php get_header(); ?>
    7.     <div id="primary" class="content-area">
    8.         <main id="main" class="site-main" role="main">
    9.         <?php while ( have_posts() ) : the_post(); ?>
    10.             <?php// get_template_part( 'content', 'page' ); ?>
    11.             <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    12.                     <div id="message" class="message-page">
    13.                         <ul>
    14.             <?php
    15.                 $query="SELECT COUNT(comment_ID) AS cnt, comment_author, comment_author_url, comment_author_email FROM (SELECT * FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->posts.ID=$wpdb->comments.comment_post_ID) WHERE comment_date > date_sub( NOW(), INTERVAL 100 MONTH ) AND user_id='0' AND comment_author_email != '' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author_email ORDER BY cnt DESC LIMIT 300";
    16.                 $wall = $wpdb->get_results($query);
    17.                 foreach ($wall as $comment)
    18.                 {
    19.                     if( $comment->comment_author_url )
    20.                     $url = $comment->comment_author_url;
    21.                     else $url="#";
    22.                     $r="rel='external nofollow'";
    23.                     $imgsize="50";
    24.                     $tmp = "<a target='_blank' href='".$url."' title='".$comment->comment_author." (留下".$comment->cnt."个脚印)'><img width='".$imgsize ."' height='".$imgsize ."' src='http://cn.gravatar.com/avatar.php?gravatar_id=".md5( strtolower($comment->comment_author_email) )."&size=".$imgsize ."&d=identicon&r=G' alt='".$comment->comment_author."(留下".$comment->cnt."个脚印)' /></a>";
    25.                     $output .= $tmp;
    26.                 }
    27.                 echo $output ;
    28.             ?>
    29.             </ul>
    30.                     </div><!-- #message -->
    31.                 </article><!-- #page -->
    32.             <?php if ( comments_open() || get_comments_number() ) : ?>
    33.                 <?php comments_template( '', true ); ?>
    34.             <?php endif; ?>
    35.         <?php endwhile; ?>
    36.         </main><!-- .site-main -->
    37.     </div><!-- .content-area -->
    38. <?php get_sidebar(); ?>
    39. <?php get_footer(); ?>

    然后,在:页面-新建页面-页面模板-选择留言板-发布。

    这样就完工了。

    如果不需要侧栏,想要宽屏,就去掉第8、45、47行即可。

    liuyan-page



沪ICP备19023445号-2号
友情链接