工作手记|为wordpress网站增加说说(类似微博)功能

说说这个功能,只要用过微博,相信大家都不陌生,因为说说就是微博,有几句话想说一说,就发布,有一定字数限制,很短。

微博说说

有时走在路上,有时趴在桌上,华哥的大脑很是活跃,会突然冒出一两个想法,用几句话能表达完毕,偏偏华哥不喜欢用那个新浪微博,也没有养成有啥说啥即时发微博的习惯。那,能不能有一种方式,把这种想法(有价值的)记录下来呢,那就是你自己网站的微博——说说。

华哥网站用的是wordpress,那有没有方法在wordpress中实现这个功能呢。查找了,有。经过实践,成功了,见:华哥的说说

本文参考的教程是:http://www.tang1314.com/website/317.html,你可以看此教程,也可以看华哥在wordpress增加说说的具体方法。

1.首先在后台添加说说的菜单,能够在后台发布说说。

wordpress说说功能

主要是操作所使用主题目录的functions.php,添加如下代码在最后面:

//说说
add_action('init', 'my_custom_init');
function my_custom_init()
{ $labels = array( 'name' => '说说',
'singular_name' => 'singularname',
'add_new' => '发表说说',
'add_new_item' => '发表说说',
'edit_item' => '编辑说说',
'new_item' => '新说说',
'view_item' => '查看说说',
'search_items' => '搜索说说',
'not_found' => '暂无说说',
'not_found_in_trash' => '没有已遗弃的说说',
'parent_item_colon' => '',
'menu_name' => '说说' );
$args = array( 'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true, 'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','author') );
register_post_type('shuoshuo',$args); }

检查无误后,上传,然后去后台,就发现,左侧的管理菜单中,就有说说。如上面的图。

2.制作一个页面模板,这个模板起名为shuoshuo.php,放在所使用的主题模板根目录下,用于显示后台所发布的说说内容。华哥的shuoshuo.php如下(相对于原教程代码,有不少的改动)

<?php /*
Template Name: 说说
*/
get_header(); ?>

<link href="/wp-content/themes/blogrow/shuoshuo.css" rel="stylesheet">
<section class="pad group">
<div class="shuoshuo">
<ul class="archives-monthlisting">
<?php query_posts("post_type=shuoshuo&post_status=publish&posts_per_page=-1");if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><span class="tt">
<?php the_time('Y年n月j日G:i'); ?>
</span><br><span >—
<?php the_author() ?>
</span>
<div class="shuoshuo-content">
<P> <b><?php the_title(); ?></b></P>
<?php the_content(); ?>

</div>
<?php endwhile;endif; ?>
</li>
</ul>
</div>
</section>
<?php get_footer(); ?>

这个页面模板对应的就是:华哥的说说 这个样子。

3.上面只是准备好了模板,还需要创建一个页面,来使用这个模板,在页面中选择新建,输入标题后,内容不要填写为空,然后重点操作是选择模板为刚才所制作的“说说”模板。

页面模板选择

上图模板中可以选择说说,那这个说说模板名称哪来的呢?模板是shuoshuo.php呀!那就要注意模板中第一行的注释了,如下:

<?php /*
Template Name: 说说
*/
get_header(); ?>

说说就是从上边来的。你可以改成任何你喜欢的名称。

4.能不能把最新发的说说,通过小工具,显示在首页或内容页的右侧呢?目前还没有找到方法和花费时间去实践。

相关文章

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注