2014/05/07
wordpress
カスタム投稿を作成
function.phpに追加記述
function info_custom_post_type()
{
register_post_type( 'kanojo_category', /* post-type */
array(
'labels' => array(
'name' => __( '投稿その2' ),
'singular_name' => __( '投稿その2' )
),
'public' => true,
'supports' => array('title','thumbnail','editor','author','excerpt','comments','custom-fields'),
'menu_position' =>5,
'has_archive' => false,
'query_var' => true,
'rewrite' => array(
'slug' => 'kanojo_category',
'with_front' => true),
'capability_type' => 'page'
)
);
register_taxonomy(
'kanojo_category-cat',
'kanojo_category',
array(
'label' => 'カテゴリー',
'singular_label' => 'カテゴリー',
'public' => true,
'show_ui' => true,
'hierarchical' => true,
'has_archive' => true,
'update_count_callback' => '_update_post_term_count',
)
);
}
add_action('init', 'info_custom_post_type');
page.php内に下記を追記してタイトル、コンテンツを表示
<?php if (have_posts()) : ?>
<?php query_posts('post_type=投稿その2&posts_per_page=5'); ?>
<?php while (have_posts()) :the_post(); ?>
<li><a href="<?php echo get_permalink($tax_post->ID); ?>"><?php the_title(); ?></a><?php the_content();?></li>
<?php endwhile;endif; ?>
<?php wp_reset_query();?>