我正在尝试循环一个函数,该函数将允许用户创建一些自定义帖子,但我对函数名有一个问题。以下是一个示例:
我该如何写:
function register_cpt_1_mdframework_price(){
…就像这样:
function $myvar(){
我就是这样解决的,但这既不好也不聪明——还有更好的主意吗?
<?php
$numcpost = of_get_option(\'how_many_custom_posts\');
do {
switch ($numcpost){
case 1:
require_once MDCP_DIR . \'cpost/cpostloop1.php\';
break;
case 2:
require_once MDCP_DIR . \'cpost/cpostloop2.php\';
break;
case 3:
require_once MDCP_DIR . \'cpost/cpostloop3.php\';
break;
case 4:
require_once MDCP_DIR . \'cpost/cpostloop4.php\';
break;
case 5:
require_once MDCP_DIR . \'cpost/cpostloop5.php\';
break;
};
--$numcpost;
}while ($numcpost > 0);
文件:cpostloop1。php
<?php
$numcpost = 1;
add_action( \'init\', \'register_cpt_\'.$numcpost.\'_mdframework_price\', $numcpost );
$singcpost = of_get_option(\'custom_posts_name_s_n\'.$numcpost.\'\');
$plurcpost = of_get_option(\'custom_posts_name_p_n\'.$numcpost.\'\');
$desccpost = of_get_option(\'custom_posts_name_d_n\'.$numcpost.\'\');
$imgcpost = of_get_option(\'custom_posts_name_i_n\'.$numcpost.\'\');
function register_cpt_1_mdframework_price(){
$labels = array(
\'name\' => _x( $plurcpost, \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'singular_name\' => _x( $singcpost, \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'add_new\' => _x( \'Add New\', \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'add_new_item\' => _x( \'Add New\'.$singcpost.\'\', \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'edit_item\' => _x( \'Edit\'.$singcpost.\'\', \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'new_item\' => _x( \'New\'.$singcpost.\'\', \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'view_item\' => _x( \'View\'.$singcpost.\'\', \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'search_items\' => _x( \'Search\'.$plurcpost.\'\', \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'not_found\' => _x( \'No \'.$plurcpost.\' found\', \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'not_found_in_trash\' => _x( \'No \'.$plurcpost.\' found in Trash\', \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'parent_item_colon\' => _x( \'Parent \'.$singcpost.\':\', \'mdframework_custom_created_post\'.$numcpost.\'\' ),
\'menu_name\' => _x( $singcpost, \'mdframework_custom_created_post\'.$numcpost.\'\' ),
);
$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\', \'high\', \'middle\', \'low\', \'special\', \'last_minute\' ),
\'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( \'mdframework_custom_created_post_\'.$numcpost.\'\', $args );
}