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

字號:


    對dedecms了解的朋友們,想必對如何獲取上一篇、下一篇文章的標簽也是非常熟悉。dedecms獲取上一篇、下一篇文章的標簽分別為:{dede:prenext get='pre'/}、{dede:prenext get='next'}。
    在這個標簽里,并沒有設置上一篇、下一篇文章標題字數(shù)的功能,那么我們又該怎樣來實現(xiàn)這樣的功能呢?其實,dedecms系統(tǒng)這點也做得很好,考慮的也挺周到,這個是可以設置的。WordPress系統(tǒng)源于一個blog平臺,慢慢地發(fā)展到今天的這樣一個功能強大的cms系統(tǒng)!
    盡管如此,但是wordpress默認情況下文章頁英文叫post, page,有時候,我們開發(fā)的時候,也許并不想要這個菜單還是顯示著post,和page,也許你想要顯示為其它的名稱,比如“產(chǎn)品”,”聯(lián)系人”亦或是其它的名稱!
    當然我們可以自己寫一個post type,移除原來的文章類型,新建的的內(nèi)容類型可以自己命名,但是其實我們還有一個更好的方法對原來系統(tǒng)的內(nèi)容類型菜單名稱進行重命名:
    看下面的一個國外的高手的代碼:
    <?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');
    ?>
    這一個代碼中就是把原來的文章post的菜單名“post”更改為Contact了!
    參考資料:http://wordpress.stackexchange.com/questions/9211/changing-admin-menu-labels
    dedecms設置上一篇、下一篇文章標題字數(shù)的方法:
    第一步:找到dedecms下“include/arc.archives.class.php”文件,用DW或記事本打開。
    第二步:查找 $this->PreNext['pre']="上一篇:{$preRow['title']}"; 在這一行上面加上 $preRow['title']=cn_substr($preRow['title'],30); ,30的意思就是30個字節(jié),也就是15個漢字。這個可以根據(jù)實際情況,自行設定。
    第三步:查找 $this->PreNext['next']="下一篇:{$nextRow['title']}"; 在這一行上面加上 $nextRow['title']=cn_substr($nextRow['title'],30); 。
    然后保存一下,至此,dedecms設置上一篇、下一篇文章標題字數(shù)的方法就完成了。怎么樣,簡單吧,如果你還在為這個犯愁,那就趕緊試試吧!