//Custom Post Type
register_post_type(\'inf_main_feature\', array(
\'labels\' => array(
\'name\' => \'Main Featured\',
\'singular_name\' => \'Main Featured\',
\'add_new\' => __( \'Add New\' ),
\'add_new_item\' => __( \'Add New Feature\' ),
\'view_item\' => \'View Feature\',
\'edit_item\' => \'Edit Story\',
\'new_item\' => __(\'New Featire\'),
\'view_item\' => __(\'View New Feature\'),
\'search_items\' => __(\'Search Features\'),
\'not_found\' => __(\'No entries found\'),
\'not_found_in_trash\' => __(\'No entries found in Trash\'),
),
\'public\' => true,
\'exclude_from_search\' => true,
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'_edit_link\' => \'post.php?post=%d\',
\'rewrite\' => array(
"slug" => "homebox",
"with_front" => false,
),
\'query_var\' => true,
\'supports\' => array(\'title\', \'editor\', \'page-attributes\', \'thumbnail\'),
));
//Custom Fields
Carbon_Container::factory(\'custom_fields\', __(\'Feature Options\', \'inf\'))
->show_on_post_type(\'inf_main_feature\')
->add_fields(array(
Carbon_Field::factory(\'text\', \'feature_url\', \'The Link\'),
Carbon_Field::factory(\'attachment\', \'main_image\', \'Main Image\')
->help_text(\'Image Dimensions - 600 × 600 pixels.\')
));
// Main Feature
function inf_feature() {
$args = array (
\'post_type\' => \'inf_main_feature\',
\'posts_per_page\' => 1
);
$feature = get_post($args)[0]->ID;
$feature_link = get_post_meta($feature->ID, \'feature_url\', true);
$main_boxID = get_post_meta($feature->ID, \'main_image\', full);
$main_image = get_post($main_boxID[0])->guid;
?>
我的HTML
div class="main_feature_container"
div class="main_feature"
a href="php echo $feature_link"
img src="php echo $main_image"
/a
/div
忘记标签<;>和<?等我对这个编辑器很在行,无法正确渲染
我无法从这个自定义帖子类型中获取图像或链接。任何帮助都将不胜感激。