我创建了一个名为portfolio的自定义帖子类型。我还创建了一个名为single portfolio的文件。php显示公文包内容。
创建公文包帖子时,我要使用的模板不会显示在属性部分下的下拉列表中。事实上,在我创建第一个公文包帖子之前,下拉列表根本不会显示,此时,下拉列表中填充了两个项目:
-(无父级)
-[第一个投资组合帖子的标题]
下面是函数中的内容。php
add_action(\'init\', \'create_portfolio\');
function create_portfolio() {
$labels = array(
\'name\' => _x(\'My Portfolio\', \'post type general name\'),
\'singular_name\' => _x(\'Portfolio Item\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'portfolio item\'),
\'add_new_item\' => __(\'Add New Portfolio Item\'),
\'edit_item\' => __(\'Edit Portfolio Item\'),
\'new_item\' => __(\'New Portfolio Item\'),
\'view_item\' => __(\'View Portfolio Item\'),
\'search_items\' => __(\'Search Portfolio\'),
\'not_found\' => __(\'Nothing found\'),
\'not_found_in_trash\' => __(\'Nothing found in Trash\'),
\'parent_item_colon\' => \'\'
);
$portfolio_args = array(
\'labels\' => $labels,
\'label\' => __(\'Portfolio\'),
\'singular_label\' => __(\'Portfolio\'),
\'public\' => true,
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'has_archive\' => true,
\'rewrite\' => array("slug" => "portfolio"),
\'can_export\' => true,
\'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'excerpt\', \'page-attributes\')
);
register_post_type(\'portfolio\',$portfolio_args);
}
和单一投资组合。php
<?php
/*
Template Name: Single Portfolio
*/
?>
<?php get_header(); ?>
<div id="main">
<?php $loop = new WP_Query(array(\'post_type\' => \'portfolio\', \'posts_per_page\' => 10));
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$custom = get_post_custom($post->ID);
$screenshot_url = $custom["screenshot_url"][0];
$website_url = $custom["website_url"][0];
$date_completed = $custom["date_completed"][0];
?>
<div id="portfolio-item">
<h1><?php the_title(); ?></h1>
<?php echo \'Completed:\'; $custom["year_completed"][0]; ?>
<a href="<?=$website_url?>"><?php the_post_thumbnail(); ?> </a>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
</div><!--MAIN-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>