wordpress 內(nèi)容類(lèi)型名稱(chēng)重命名方法

字號(hào):


    對(duì)dedecms了解的朋友們,想必對(duì)如何獲取上一篇、下一篇文章的標(biāo)簽也是非常熟悉。dedecms獲取上一篇、下一篇文章的標(biāo)簽分別為:{dede:prenext get='pre'/}、{dede:prenext get='next'}。
    在這個(gè)標(biāo)簽里,并沒(méi)有設(shè)置上一篇、下一篇文章標(biāo)題字?jǐn)?shù)的功能,那么我們又該怎樣來(lái)實(shí)現(xiàn)這樣的功能呢?其實(shí),dedecms系統(tǒng)這點(diǎn)也做得很好,考慮的也挺周到,這個(gè)是可以設(shè)置的。wordpress系統(tǒng)源于一個(gè)blog平臺(tái),慢慢地發(fā)展到今天的這樣一個(gè)功能強(qiáng)大的cms系統(tǒng)!
    盡管如此,但是wordpress默認(rèn)情況下文章頁(yè)英文叫post, page,有時(shí)候,我們開(kāi)發(fā)的時(shí)候,也許并不想要這個(gè)菜單還是顯示著post,和page,也許你想要顯示為其它的名稱(chēng),比如“產(chǎn)品”,”聯(lián)系人”亦或是其它的名稱(chēng)!
    當(dāng)然我們可以自己寫(xiě)一個(gè)post type,移除原來(lái)的文章類(lèi)型,新建的的內(nèi)容類(lèi)型可以自己命名,但是其實(shí)我們還有一個(gè)更好的方法對(duì)原來(lái)系統(tǒng)的內(nèi)容類(lèi)型菜單名稱(chēng)進(jìn)行重命名:
    看下面的一個(gè)國(guó)外的高手的代碼:
    <?php 
    function change_post_menu_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'contacts';
    $submenu['edit.php'][5][0] = 'contacts';
    $submenu['edit.php'][10][0] = 'add contacts';
    $submenu['edit.php'][15][0] = 'status'; // change name for categories
    $submenu['edit.php'][16][0] = 'labels'; // change name for tags
    echo '';
    }
    function change_post_object_label() {
    global $wp_post_types;
    $labels = &$wp_post_types['post']->labels;
    $labels->name = 'contacts';
    $labels->singular_name = 'contact';
    $labels->add_new = 'add contact';
    $labels->add_new_item = 'add contact';
    $labels->edit_item = 'edit contacts';
    $labels->new_item = 'contact';
    $labels->view_item = 'view contact';
    $labels->search_items = 'search contacts';
    $labels->not_found = 'no contacts found';
    $labels->not_found_in_trash = 'no contacts found in trash';
    }
    add_action( 'init', 'change_post_object_label' );
    add_action( 'admin_menu', 'change_post_menu_label' );
    to change the menu order, go with this:
    // customize admin menu order
    function custom_menu_order($menu_ord) {
    if (!$menu_ord) return true;
    return array(
    'index.php', // this represents the dashboard link
    'edit.php', //the posts tab
    'upload.php', // the media manager
    'edit.php?post_type=page', //the posts tab
    );
    }
    add_filter('custom_menu_order', 'custom_menu_order');
    add_filter('menu_order', 'custom_menu_order');
    ?>
    這一個(gè)代碼中就是把原來(lái)的文章post的菜單名“post”更改為contact了!
    參考資料:http://wordpress.stackexchange.com/questions/9211/changing-admin-menu-labels
    dedecms設(shè)置上一篇、下一篇文章標(biāo)題字?jǐn)?shù)的方法:
    第一步:找到dedecms下“include/arc.archives.class.php”文件,用dw或記事本打開(kāi)。
    第二步:查找 $this->prenext['pre']=上一篇:{$prerow['title']}; 在這一行上面加上 $prerow['title']=cn_substr($prerow['title'],30); ,30的意思就是30個(gè)字節(jié),也就是15個(gè)漢字。這個(gè)可以根據(jù)實(shí)際情況,自行設(shè)定。
    第三步:查找 $this->prenext['next']=下一篇:{$nextrow['title']}; 在這一行上面加上 $nextrow['title']=cn_substr($nextrow['title'],30); 。
    然后保存一下,至此,dedecms設(shè)置上一篇、下一篇文章標(biāo)題字?jǐn)?shù)的方法就完成了。怎么樣,簡(jiǎn)單吧,如果你還在為這個(gè)犯愁,那就趕緊試試吧!