久久久精品2019免费观看_亚洲国产精品成人久久久_69国产成人综合久久精品91_国产精品久久精品视

wordpress網站增加說說(類似微博)功能

1.首先在后臺添加說說的菜單,能夠在后臺發(fā)布說說。

 

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

//說說

add_action(‘in

function my_custom_init()

{ $labels = array( ‘name’ => ‘說說’,

‘singular_name’ => ‘singularname’,

‘add_new’ => ‘發(fā)表說說’,

‘add_new_item’ => ‘發(fā)表說說’,

‘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); }

檢查無誤后,上傳,然后去后臺,就發(fā)現,左側的管理菜單中,就有說說。如上面的圖。

2.制作一個頁面模板,這個模板起名為shuoshuo.php,放在所使用的主題模板根目錄下,用于顯示后臺所發(fā)布的說說內容。華哥的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.上面只是準備好了模板,還需要創(chuàng)建一個頁面,來使用這個模板,在頁面中選擇新建,輸入標題后,內容不要填寫為空,然后重點操作是選擇模板為剛才所制作的“說說”模板。

 

上圖模板中可以選擇說說,那這個說說模板名稱哪來的呢?模板是shuoshuo.php呀!那就要注意模板中第一行的注釋了,如下:

<?php /*

Template Name: 說說

*/

get_header(); ?>

說說就是從上邊來的。你可以改成任何你喜歡的名稱。

4.能不能把最新發(fā)的說說,通過小工具,顯示在首頁或內容頁的右側呢?目前還沒有找到方法和花費時間去實踐。

未經允許不得轉載:445IT之家 » wordpress網站增加說說(類似微博)功能

贊 (0) 打賞

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

微信掃一掃打賞