WordPress 內(nèi)容類型名稱重命名方法

字號(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í)候,我們開發(fā)的時(shí)候,也許并不想要這個(gè)菜單還是顯示著post,和page,也許你想要顯示為其它的名稱,比如“產(chǎn)品”,”聯(lián)系人”亦或是其它的名稱!
    當(dāng)然我們可以自己寫一個(gè)post type,移除原來(lái)的文章類型,新建的的內(nèi)容類型可以自己命名,但是其實(shí)我們還有一個(gè)更好的方法對(duì)原來(lái)系統(tǒng)的內(nèi)容類型菜單名稱進(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或記事本打開。
    第二步:查找 $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è)犯愁,那就趕緊試試吧!