<?php echo get_the_term_list($post->ID, 'chiiki_shurui'); ?> <?php echo get_the_term_list($post->ID, 'タクソノミー名'); ?>
タグ: ターム
タームをタックスクエリー入れ込む方法![]は配列をしまうってことだ!多分
<?php //ターム名リンク無しで取得
$terms = get_the_terms($post->ID, 'art_name');
$names = array();
echo ""; //前の文字
foreach ( $terms as $term ) {
$names[] = $term->slug; //[]にしまうってこと!
}
?>
<?php
$r_posts1 = $cfs->get('kanren_art');
if ($r_posts1) :
?>
<div class="top_titol" style="font-size:24px;">関連アーティースト</div>
<div class="top_new_item_all">
<?php
endif;
?>
<?php //---------------------------------------------関連イベント
$args = array(
'posts_per_page' => -1,
//'orderby' => 'menu_order',
//'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'art_name',
'field' => 'slug',
'terms' => array($names[0],$names[1],$names[2],$names[3],$names[4],$names[5],$names[6],$names[7],$names[8],$names[9],$names[10]),
//'operator'=>'NOT IN'
),
),
'post_type' => 'support_artists', //カスタム投稿名
);
?>
<?php
query_posts( $args );
?>
<?php
if ( have_posts () ) :
while ( have_posts() ) :
the_post();
?>
<a href="<?php the_permalink(); ?>"><div class="artists_box">
<div class="artist_sam">
<?php //写真1枚----------------------------
$title= get_the_title();
$attachment_id = $cfs->get('w126');
$sample_photo = wp_get_attachment_image($attachment_id, 'W126',0,array('alt'=>$title,'title'=>$title));
echo $sample_photo;
?></div>
<div class="artist_disp">
<div class="artist_name"><?php the_title(); ?></div>
<div class="artist_area"><?php echo nl2br(get_post_meta($post->ID,"chiiki",true)); ?></div>
</div>
</div></a>
<!--/Aritist_box-->
<?php
endwhile;?>
<br clear="all" />
</div>
<?php
endif;
?>
<?php wp_reset_query(); ?>
カテゴリ系のまとめ
<?php //カテゴリーページでカテゴリー名を取得 りんくなし $cat_d = get_the_category(); $cat_d = $cat_d[0]; $cat_name_d = $cat_d->cat_name; echo $cat_name_d; ?>
上記 記事が無いとでないため
<?php single_term_title(); ?>
こっち
かてID2へのリンク
<a href="<?php echo get_category_link('2');?>">活動報告をもっと見る▶</a>
リンクつき記事のカテゴリ出力
<?php the_category(', '); ?>
ターム名とは別の名前を出力 デフォルト機能
タームの場合ディスプリクションを使う
<?php //カテゴリー・タグ情報を取得(slug,アーカイブページでターム名取得,タクソノミー名取得)
$term3 = get_term_by('slug',get_query_var( 'term' ),get_query_var( 'taxonomy' ));
echo $term3->description; //現在ターム位置所得
?>
タクソノミーページ(アーカイブ)などで
<?php //アーカイブページでターム名取得 $super1 = get_query_var( 'term' ); echo $super1 ?> <?php //アーカイブページでタクソノミー名取得 $super2 = get_query_var( 'taxonomy' ); echo $super2 ?>
スラッグが'blog'のカテゴリー情報を取得する。 <?php $cat = get_term_by( 'slug' , 'blog' , 'category' ); ?>
http://elearn.jp/wpman/function/get_term_by.html
ここよりゲットタームバイの返り値は
| プロパティ名 | データ型 | 意味 |
|---|---|---|
| term_id | int | ID |
| name | string | 名前 |
| slug | string | スラッグ |
| term_group | int | グループID |
| term_taxonomy_id | int | タクソノミーID |
| taxonomy | string | タクソノミー名。カテゴリーの場合は’category’、タグの場合は’post_tag’となる |
| description | string | 説明 |
| parent | int | 親カテゴリーID。親カテゴリーがない場合は0となる |
| count | int | 投稿数 |
複合
<?php //カテゴリー・タグ情報を取得(slug,アーカイブページでターム名取得,タクソノミー名取得)
$term = get_term_by('slug',get_query_var( 'term' ),get_query_var( 'taxonomy' )
);
?>
そこで分岐する
<?php //$termにはいってる情報で分岐
if ( $term->parent ) { // 親IDが入ってれば (子だったら)
wp_list_categories( array(
'taxonomy' => get_query_var( 'taxonomy' ),
'child_of' => $term->parent,//親のIDを出力
'hide_empty' => 0,
) );
}
else { //親だったらそのまま出力
wp_list_categories( array(
'taxonomy' => get_query_var( 'taxonomy' ),
'child_of' => $term->term_id,
'hide_empty' => 0,
) );
}?>
カテゴリ wp_list_categories
<?php wp_list_categories(array( 'title_li' => '',//最初に何も入れない 入れると<li class="categories">入れた文字<ul>リスト一覧</ul></li>となる 'taxonomy' => 'category', //カテゴリ 'hide_empty' => 0, //記事がなくとも表示 'orderby' => 'order',//順番は指定します 'depth' => 1//子は表示しません。 )); ?>
http://wpdocs.sourceforge.jp/テンプレートタグ/wp_list_categories
ディスプリクションのキーワードにタグ名とターム名を入れる
<META name="keywords" content="<?php //ターム名リンク無しで取得
$terms = wp_get_post_terms( $post->ID, 'genre' ); //分類で設定した名称
$names = array();
echo ""; //前の文字
foreach ( $terms as $term ) {
$names[] = $term->name;
}
echo implode( ',', $names ); //区切り文字を指定
?><?php
$terms = wp_get_post_terms( $post->ID, 'chiiki2' ); //分類で設定した名称
$names = array();
echo ","; //前の文字
foreach ( $terms as $term ) {
$names[] = $term->name;
}
echo implode( ',', $names ); //区切り文字を指定
?><?php //タグ名リンク無しで取得
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ',';
}
}
?>">
ターム名リンク無しで取得
<?php //ターム名リンク無しで取得
$terms = wp_get_post_terms( $post->ID, 'genre' ); //分類で設定した名称
$names = array();
echo ""; //前の文字
foreach ( $terms as $term ) {
$names[] = $term->name;
}
echo implode( ',', $names ); //区切り文字を指定
?>