文章最后更新时间:2024年04月14日
【使用方法:】
- 1、新建微语说说功能:将下面的代码复制粘贴到你主题的functions.php函数文件中,为Wordpress添加微语说说功能。添加完成后,应该可以在Wordpress后台菜单中找到“说说”这一项了。
//说说 add_action('init', 'my_custom_init'); function my_custom_init() { $labels = array( 'name' => '说说', 'singular_name' => '说说', '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, 'exclude_from_search' =>true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => false, 'hierarchical' => false, 'menu_position' => null, 'supports' => array('editor','author','title', 'custom-fields') ); register_post_type('shuoshuo',$args); } //说说的固定连接格式 function custom_shuoshuo_link( $link, $post = 0 ){ if ( $post->post_type == 'shuoshuo' ){ return home_url( 'shuoshuo/' . $post->ID .'.html' ); } else { return $link; } } add_filter('post_type_link', 'custom_shuoshuo_link', 1, 3); function custom_shuoshuo_rewrites_init(){ add_rewrite_rule( 'shuoshuo/([0-9]+)?.html$', 'index.php?post_type=shuoshuo&p=$matches[1]', 'top' ); } add_action( 'init', 'custom_shuoshuo_rewrites_init' );
2、添加微语说说模板:新建一个page-shuoshuo.php文件,将下面代码复制进去,上传到你主题的pages目录。
折腾网提示您如需查看,请先回复并刷新本帖!
3、创建一个新页面:进入Wordpress后台,创建一个新页面,在模板一栏中选择“说说”,没错,就是我们上一步添加到pages目录下的那个模板。然后确认新建即可。这时候,wordpress的微语说说功能就基本实现了。只要将新建的页面添加到你的菜单中,就可以正常发表说说了,但是样式是非常简陋的,所以下一步才是最关键的——选择适合自己CSS样式。
折腾网提示您如需查看,请先回复并刷新本帖!
发表评论