2012 年 4 月 15 日
アーカイブ(カテゴリー)ページのテンプレートの読み込みの順番
1 taxonomy-{taxonomy}-{term}.php
分類名が「chihuahua」で スラッグが「puppy」の場合は taxonomy-chihuahua-puppy.php
2 taxonomy-{taxonomy}.php
分類名が「poodle」の場合は taxonomy-poodle.php
3 taxonomy.php
4 archive.php
5 index.php
カスタム投稿タイプの一連の記事は、Web Design RECIPESさんより転記させていただきました。
カテゴリー: 仕事関係 | コメントは受け付けていません。
2012 年 4 月 15 日
普通にしてたら「single.php」を使っちゃいます。
なので 「single-カスタム投稿の名前.php」を作りましょう。
カテゴリー: WordPress覚え書き | コメントは受け付けていません。
2012 年 4 月 15 日
カスタム投稿を作っただけだと トップページに表示されません。><
なので「index.php」に↓を書く。
<?php
/* カスタム投稿タイプを表示する */
$loop = new WP_Query( array( ‘post_type’ => ‘chihuahua‘, ‘posts_per_page’ => 10 ) );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<h3><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></h3>
/* カスタム分類を表示 */
<p>
<?php echo get_the_term_list( $post->ID, ‘chihuahua-cat’, ‘puppy‘, ‘, ‘, ” ); ?>
</p>
/* コンテンツ */
<div>
<?php the_content(‘続きを読む»’); ?>
</div>
<?php endwhile; ?>
トップページに10件表示させるって設定です。
※get_the_term_list( $post->ID, ‘タクソノミーの名前’, ‘前に表示する文字’, ‘区切り文字’, ‘後ろに表示する文字’ )
カテゴリー: WordPress覚え書き | コメントは受け付けていません。
2012 年 4 月 15 日
「functions.php」に前の投稿の前半を変更して書く。
/* カスタム投稿タイプ */
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'chihuahua',
array(
'labels' => array(
'name' => __( 'チワワ' ),
'singular_name' => __( 'チワワ' )
),
'public' => true,
'menu_position' => 5,
/* ここから */
'supports' => array('title','editor','thumbnail',
'custom-fields','excerpt','author','trackbacks',
'comments','revisions','page-attributes')
/* ここまで */
)
);
==後半省略==
}
カテゴリー: WordPress覚え書き | コメントは受け付けていません。
2012 年 4 月 15 日
このカスタム投稿内のカテゴリーの事を「カスタムタクソノミー」と言う。
「functions.php」に↓を書く。
/* カスタム投稿タイプ */
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'chihuahua', /* post-type */
array(
'labels' => array(
'name' => __( 'チワワ' ),
'singular_name' => __( 'チワワ' )
),
'public' => true,
'menu_position' => 5,
)
);
/* ここから */
register_taxonomy(
'chihuahua-cat', /* タクソノミーの名前 */
'chihuahua', /* chihuahua投稿で設定する */
array(
'hierarchical' => true, /* 親子関係が必要なければ false */
'update_count_callback' => '_update_post_term_count',
'label' => '子犬',
'singular_label' => '子犬',
'public' => true,
'show_ui' => true
)
);
/* ここまでを追加 */
}
カテゴリー: WordPress覚え書き | コメントは受け付けていません。