自定义帖子未按预期工作

时间:2013-04-22 作者:Downloadtaky

NEW EDIT 正如我在回答中所写的那样,我解决了变量被“遗忘”的问题(我知道不是那么技术性,对此很抱歉),当function 开始。

EDIT: 我发现问题是:\'name\' => _x( $plurcpost, $singcpost ),如果我使用文本而不是变量,那么一切都会正常工作。。。。那么,如何在这里使用变量呢?

我正在使用wptheming选项框架开发一个新的WordPress模板。用户可以使用单选功能选择自己想要的自定义帖子数量(1到5篇之间)。收音机的值存储在DB中,然后存储在函数中。php需要“包含”正确的php文件。“include”按预期工作(我试图删除此项:<?php 在每个文件的开头,我可以在我的管理屏幕上看到包含的文件)。我认为问题可能是未保存的选项,但我尝试回应其中的每一个选项,我没有问题。因此,我认为我在生成cpost的文件中做错了什么。

这就是我的函数。php:

/* Include Custom-posts settings */
if (of_get_option(\'custom_custom_post_creator\')){//this is working
    $quanticpost = of_get_option(\'how_many_custom_posts\');//this is working too
require_once MDCP_DIR . \'cpost/cpost_if_\'.$quanticpost.\'.php\';//this is working too
};
这是cpost\\u if\\u 5。php:

<?php
    /* IF 1 Start */
    $singcpost = of_get_option(\'custom_posts_name_s_n1\');
    $plurcpost = of_get_option(\'custom_posts_name_p_n1\');
    $desccpost = of_get_option(\'custom_posts_name_d_n1\');
    $imgcpost  = of_get_option(\'custom_posts_name_i_n1\');
add_action( \'init\', \'register_cpt_cpost_mdframework_1\' );

function register_cpt_cpost_mdframework_1() {

    $labels = array( 
        \'name\' => _x( $plurcpost, $singcpost ),
        \'singular_name\' => _x( $singcpost, $singcpost ),
        \'add_new\' => _x( \'Add New\', $singcpost ),
        \'add_new_item\' => _x( \'Add New \'.$singcpost.\'\', $singcpost ),
        \'edit_item\' => _x( \'Edit \'.$singcpost.\'\', $singcpost ),
        \'new_item\' => _x( \'New \'.$singcpost.\'\', $singcpost ),
        \'view_item\' => _x( \'View \'.$singcpost.\'\', $singcpost ),
        \'search_items\' => _x( \'Search \'.$plurcpost.\'\', $singcpost ),
        \'not_found\' => _x( \'No \'.$plurcpost.\' found\', $singcpost ),
        \'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', $singcpost ),
        \'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', $singcpost ),
        \'menu_name\' => _x( $plurcpost, $singcpost ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => $desccpost,
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'customtax1\', \'customtax2\', \'customtax3\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => $imgcpost,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( $singcpost, $args );
}
/* IF 1 END */
    /* IF 2 Start */
    $singcpost = of_get_option(\'custom_posts_name_s_n2\');
    $plurcpost = of_get_option(\'custom_posts_name_p_n2\');
    $desccpost = of_get_option(\'custom_posts_name_d_n2\');
    $imgcpost  = of_get_option(\'custom_posts_name_i_n2\');
add_action( \'init\', \'register_cpt_cpost_mdframework_2\' );

function register_cpt_cpost_mdframework_2() {

    $labels = array( 
        \'name\' => _x( $plurcpost, $singcpost ),
        \'singular_name\' => _x( $singcpost, $singcpost ),
        \'add_new\' => _x( \'Add New\', $singcpost ),
        \'add_new_item\' => _x( \'Add New \'.$singcpost.\'\', $singcpost ),
        \'edit_item\' => _x( \'Edit \'.$singcpost.\'\', $singcpost ),
        \'new_item\' => _x( \'New \'.$singcpost.\'\', $singcpost ),
        \'view_item\' => _x( \'View \'.$singcpost.\'\', $singcpost ),
        \'search_items\' => _x( \'Search \'.$plurcpost.\'\', $singcpost ),
        \'not_found\' => _x( \'No \'.$plurcpost.\' found\', $singcpost ),
        \'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', $singcpost ),
        \'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', $singcpost ),
        \'menu_name\' => _x( $plurcpost, $singcpost ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => $desccpost,
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'customtax1\', \'customtax2\', \'customtax3\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => $imgcpost,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( $singcpost, $args );
}
/* IF 2 END */
    /* IF 3 Start */
    $singcpost = of_get_option(\'custom_posts_name_s_n3\');
    $plurcpost = of_get_option(\'custom_posts_name_p_n3\');
    $desccpost = of_get_option(\'custom_posts_name_d_n3\');
    $imgcpost  = of_get_option(\'custom_posts_name_i_n3\');
add_action( \'init\', \'register_cpt_cpost_mdframework_3\' );

function register_cpt_cpost_mdframework_3() {

    $labels = array( 
        \'name\' => _x( $plurcpost, $singcpost ),
        \'singular_name\' => _x( $singcpost, $singcpost ),
        \'add_new\' => _x( \'Add New\', $singcpost ),
        \'add_new_item\' => _x( \'Add New \'.$singcpost.\'\', $singcpost ),
        \'edit_item\' => _x( \'Edit \'.$singcpost.\'\', $singcpost ),
        \'new_item\' => _x( \'New \'.$singcpost.\'\', $singcpost ),
        \'view_item\' => _x( \'View \'.$singcpost.\'\', $singcpost ),
        \'search_items\' => _x( \'Search \'.$plurcpost.\'\', $singcpost ),
        \'not_found\' => _x( \'No \'.$plurcpost.\' found\', $singcpost ),
        \'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', $singcpost ),
        \'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', $singcpost ),
        \'menu_name\' => _x( $plurcpost, $singcpost ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => $desccpost,
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'customtax1\', \'customtax2\', \'customtax3\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => $imgcpost,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( $singcpost, $args );
}
/* IF 3 END */
    /* IF 4 Start */
    $singcpost = of_get_option(\'custom_posts_name_s_n4\');
    $plurcpost = of_get_option(\'custom_posts_name_p_n4\');
    $desccpost = of_get_option(\'custom_posts_name_d_n4\');
    $imgcpost  = of_get_option(\'custom_posts_name_i_n4\');
add_action( \'init\', \'register_cpt_cpost_mdframework_4\' );

function register_cpt_cpost_mdframework_4() {

    $labels = array( 
        \'name\' => _x( $plurcpost, $singcpost ),
        \'singular_name\' => _x( $singcpost, $singcpost ),
        \'add_new\' => _x( \'Add New\', $singcpost ),
        \'add_new_item\' => _x( \'Add New \'.$singcpost.\'\', $singcpost ),
        \'edit_item\' => _x( \'Edit \'.$singcpost.\'\', $singcpost ),
        \'new_item\' => _x( \'New \'.$singcpost.\'\', $singcpost ),
        \'view_item\' => _x( \'View \'.$singcpost.\'\', $singcpost ),
        \'search_items\' => _x( \'Search \'.$plurcpost.\'\', $singcpost ),
        \'not_found\' => _x( \'No \'.$plurcpost.\' found\', $singcpost ),
        \'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', $singcpost ),
        \'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', $singcpost ),
        \'menu_name\' => _x( $plurcpost, $singcpost ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => $desccpost,
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'customtax1\', \'customtax2\', \'customtax3\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => $imgcpost,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( $singcpost, $args );
}
/* IF 4 END */
    /* IF 5 Start */
    $singcpost = of_get_option(\'custom_posts_name_s_n5\');
    $plurcpost = of_get_option(\'custom_posts_name_p_n5\');
    $desccpost = of_get_option(\'custom_posts_name_d_n5\');
    $imgcpost  = of_get_option(\'custom_posts_name_i_n5\');
add_action( \'init\', \'register_cpt_cpost_mdframework_5\' );

function register_cpt_cpost_mdframework_5() {

    $labels = array( 
        \'name\' => _x( $plurcpost, $singcpost ),
        \'singular_name\' => _x( $singcpost, $singcpost ),
        \'add_new\' => _x( \'Add New\', $singcpost ),
        \'add_new_item\' => _x( \'Add New \'.$singcpost.\'\', $singcpost ),
        \'edit_item\' => _x( \'Edit \'.$singcpost.\'\', $singcpost ),
        \'new_item\' => _x( \'New \'.$singcpost.\'\', $singcpost ),
        \'view_item\' => _x( \'View \'.$singcpost.\'\', $singcpost ),
        \'search_items\' => _x( \'Search \'.$plurcpost.\'\', $singcpost ),
        \'not_found\' => _x( \'No \'.$plurcpost.\' found\', $singcpost ),
        \'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', $singcpost ),
        \'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', $singcpost ),
        \'menu_name\' => _x( $plurcpost, $singcpost ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => $desccpost,
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'customtax1\', \'customtax2\', \'customtax3\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => $imgcpost,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( $singcpost, $args );
}
/* IF 5 END */
    ;?>
这就是我在后端看到的,即使理论上有5个自定义帖子处于活动状态。This is what I can see in the backend

这是我尝试添加自定义帖子时的url:

wp管理员/新发布。php?post\\U类型=

我认为这个问题与我的自定义邮政编码有关,但我找不到我做错了什么。也许自定义post代码并不像我想的那样读取变量?

1 个回复
最合适的回答,由SO网友:Downloadtaky 整理而成

好吧,我解决了,也许不是问我应该多喝一杯咖啡或多睡点什么,无论如何,解决办法是移动这部分:

$singcpost = of_get_option(\'custom_posts_name_s_n1\');
$plurcpost = of_get_option(\'custom_posts_name_p_n1\');
$desccpost = of_get_option(\'custom_posts_name_d_n1\');
$imgcpost  = of_get_option(\'custom_posts_name_i_n1\');
打开函数后。。。

以下是更正的代码:

<?php
    /* IF 1 Start */
add_action( \'init\', \'register_cpt_cpost_mdframework_1\' );

function register_cpt_cpost_mdframework_1() {
    $singcpost = of_get_option(\'custom_posts_name_s_n1\');
    $plurcpost = of_get_option(\'custom_posts_name_p_n1\');
    $desccpost = of_get_option(\'custom_posts_name_d_n1\');
    $imgcpost  = of_get_option(\'custom_posts_name_i_n1\');
    $labels = array( 
        \'name\' => _x( $plurcpost, $singcpost ),
        \'singular_name\' => _x( $singcpost, $singcpost ),
        \'add_new\' => _x( \'Add New\', $singcpost ),
        \'add_new_item\' => _x( \'Add New \'.$singcpost.\'\', $singcpost ),
        \'edit_item\' => _x( \'Edit \'.$singcpost.\'\', $singcpost ),
        \'new_item\' => _x( \'New \'.$singcpost.\'\', $singcpost ),
        \'view_item\' => _x( \'View \'.$singcpost.\'\', $singcpost ),
        \'search_items\' => _x( \'Search \'.$plurcpost.\'\', $singcpost ),
        \'not_found\' => _x( \'No \'.$plurcpost.\' found\', $singcpost ),
        \'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', $singcpost ),
        \'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', $singcpost ),
        \'menu_name\' => _x( $plurcpost, $singcpost ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => $desccpost,
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'customtax1\', \'customtax2\', \'customtax3\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => $imgcpost,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( $singcpost, $args );
}
/* IF 1 END */
    /* IF 2 Start */
add_action( \'init\', \'register_cpt_cpost_mdframework_2\' );

function register_cpt_cpost_mdframework_2() {
    $singcpost = of_get_option(\'custom_posts_name_s_n2\');
    $plurcpost = of_get_option(\'custom_posts_name_p_n2\');
    $desccpost = of_get_option(\'custom_posts_name_d_n2\');
    $imgcpost  = of_get_option(\'custom_posts_name_i_n2\');
    $labels = array( 
        \'name\' => _x( $plurcpost, $singcpost ),
        \'singular_name\' => _x( $singcpost, $singcpost ),
        \'add_new\' => _x( \'Add New\', $singcpost ),
        \'add_new_item\' => _x( \'Add New \'.$singcpost.\'\', $singcpost ),
        \'edit_item\' => _x( \'Edit \'.$singcpost.\'\', $singcpost ),
        \'new_item\' => _x( \'New \'.$singcpost.\'\', $singcpost ),
        \'view_item\' => _x( \'View \'.$singcpost.\'\', $singcpost ),
        \'search_items\' => _x( \'Search \'.$plurcpost.\'\', $singcpost ),
        \'not_found\' => _x( \'No \'.$plurcpost.\' found\', $singcpost ),
        \'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', $singcpost ),
        \'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', $singcpost ),
        \'menu_name\' => _x( $plurcpost, $singcpost ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => $desccpost,
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'customtax1\', \'customtax2\', \'customtax3\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => $imgcpost,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( $singcpost, $args );
}
/* IF 2 END */
    /* IF 3 Start */    
add_action( \'init\', \'register_cpt_cpost_mdframework_3\' );

function register_cpt_cpost_mdframework_3() {
    $singcpost = of_get_option(\'custom_posts_name_s_n3\');
    $plurcpost = of_get_option(\'custom_posts_name_p_n3\');
    $desccpost = of_get_option(\'custom_posts_name_d_n3\');
    $imgcpost  = of_get_option(\'custom_posts_name_i_n3\');
    $labels = array( 
        \'name\' => _x( $plurcpost, $singcpost ),
        \'singular_name\' => _x( $singcpost, $singcpost ),
        \'add_new\' => _x( \'Add New\', $singcpost ),
        \'add_new_item\' => _x( \'Add New \'.$singcpost.\'\', $singcpost ),
        \'edit_item\' => _x( \'Edit \'.$singcpost.\'\', $singcpost ),
        \'new_item\' => _x( \'New \'.$singcpost.\'\', $singcpost ),
        \'view_item\' => _x( \'View \'.$singcpost.\'\', $singcpost ),
        \'search_items\' => _x( \'Search \'.$plurcpost.\'\', $singcpost ),
        \'not_found\' => _x( \'No \'.$plurcpost.\' found\', $singcpost ),
        \'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', $singcpost ),
        \'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', $singcpost ),
        \'menu_name\' => _x( $plurcpost, $singcpost ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => $desccpost,
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'customtax1\', \'customtax2\', \'customtax3\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => $imgcpost,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( $singcpost, $args );
}
/* IF 3 END */
    /* IF 4 Start */
add_action( \'init\', \'register_cpt_cpost_mdframework_4\' );

function register_cpt_cpost_mdframework_4() {
    $singcpost = of_get_option(\'custom_posts_name_s_n4\');
    $plurcpost = of_get_option(\'custom_posts_name_p_n4\');
    $desccpost = of_get_option(\'custom_posts_name_d_n4\');
    $imgcpost  = of_get_option(\'custom_posts_name_i_n4\');
    $labels = array( 
        \'name\' => _x( $plurcpost, $singcpost ),
        \'singular_name\' => _x( $singcpost, $singcpost ),
        \'add_new\' => _x( \'Add New\', $singcpost ),
        \'add_new_item\' => _x( \'Add New \'.$singcpost.\'\', $singcpost ),
        \'edit_item\' => _x( \'Edit \'.$singcpost.\'\', $singcpost ),
        \'new_item\' => _x( \'New \'.$singcpost.\'\', $singcpost ),
        \'view_item\' => _x( \'View \'.$singcpost.\'\', $singcpost ),
        \'search_items\' => _x( \'Search \'.$plurcpost.\'\', $singcpost ),
        \'not_found\' => _x( \'No \'.$plurcpost.\' found\', $singcpost ),
        \'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', $singcpost ),
        \'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', $singcpost ),
        \'menu_name\' => _x( $plurcpost, $singcpost ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => $desccpost,
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'customtax1\', \'customtax2\', \'customtax3\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => $imgcpost,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( $singcpost, $args );
}
/* IF 4 END */
    /* IF 5 Start */
add_action( \'init\', \'register_cpt_cpost_mdframework_5\' );

function register_cpt_cpost_mdframework_5() {
    $singcpost = of_get_option(\'custom_posts_name_s_n5\');
    $plurcpost = of_get_option(\'custom_posts_name_p_n5\');
    $desccpost = of_get_option(\'custom_posts_name_d_n5\');
    $imgcpost  = of_get_option(\'custom_posts_name_i_n5\');
    $labels = array( 
        \'name\' => _x( $plurcpost, $singcpost ),
        \'singular_name\' => _x( $singcpost, $singcpost ),
        \'add_new\' => _x( \'Add New\', $singcpost ),
        \'add_new_item\' => _x( \'Add New \'.$singcpost.\'\', $singcpost ),
        \'edit_item\' => _x( \'Edit \'.$singcpost.\'\', $singcpost ),
        \'new_item\' => _x( \'New \'.$singcpost.\'\', $singcpost ),
        \'view_item\' => _x( \'View \'.$singcpost.\'\', $singcpost ),
        \'search_items\' => _x( \'Search \'.$plurcpost.\'\', $singcpost ),
        \'not_found\' => _x( \'No \'.$plurcpost.\' found\', $singcpost ),
        \'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', $singcpost ),
        \'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', $singcpost ),
        \'menu_name\' => _x( $plurcpost, $singcpost ),
    );

    $args = array( 
        \'labels\' => $labels,
        \'hierarchical\' => true,
        \'description\' => $desccpost,
        \'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'page-attributes\' ),
        \'taxonomies\' => array( \'category\', \'post_tag\', \'page-category\', \'customtax1\', \'customtax2\', \'customtax3\' ),
        \'public\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 5,
        \'menu_icon\' => $imgcpost,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'has_archive\' => true,
        \'query_var\' => true,
        \'can_export\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\'
    );

    register_post_type( $singcpost, $args );
}
/* IF 5 END */
    ;?>

结束

相关推荐

如果未找到粘滞的帖子,则强制index.php Have_Posts()循环退出

我目前正在使用下面的代码在我的索引上列出粘性帖子。php。但是,当没有粘性帖子时,它会加载最新的帖子(最多显示“设置>阅读>博客帖子”中指定的数量)。我如何修改脚本,以便在并没有粘性帖子的情况下,它会暂时退出?query_posts(array(\'post__in\'=>get_option(\'sticky_posts\'))); if (have_posts()) : while (have_posts()) : the_post();