<?php //カテゴリー・タグ情報を取得(slug,アーカイブページでターム名取得,タクソノミー名取得) $term = get_term_by('slug',get_query_var( 'term' ),get_query_var( 'taxonomy' ) ); ?> <?php //$termにはいってる情報で分岐 if ( $term->parent ) { // 親IDが入ってれば (子だったら) ?> <!---TOP部分--> <?php //親のIDを取得してターム情報を引き出す。 $ido=$term->parent; $term2=get_term($ido,get_query_var( 'taxonomy' )); ?> <a href="<?php //子 親のターム情報からターム名とリンクを引き出す。 echo get_term_link($term2->slug,get_query_var( 'taxonomy' )); ?> "> <?php echo $term2->name; ?> </a> <div style="clear:both"></div> <!---一覧部分--> <?php wp_list_categories( array( 'title_li' => '', 'taxonomy' => get_query_var( 'taxonomy' ), 'child_of' => $term->parent,//親のIDを出力 'hide_empty' => 0, ) ); } else { //親だったらそのまま出力 ?> <!---TOP部分--> <a href="<?php //親 echo get_term_link($term->slug,get_query_var( 'taxonomy' )); ?> "> <?php echo $term->name; ?> </a> <div style="clear:both"></div> <!---一覧部分--> <?php wp_list_categories( array( 'title_li' => '', 'taxonomy' => get_query_var( 'taxonomy' ), 'child_of' => $term->term_id, 'hide_empty' => 0, ) ); }?>
日: 2013年11月10日
アロー演算子
codeigniterでDBアクセス時に用いるもの
http://codeigniter.jp/user_guide_ja/database/examples.html
$query = $this->db->query('SELECT name, title, email FROM my_table'); foreach ($query->result() as $row) { echo $row->title; echo $row->name; echo $row->email; } echo 'Total Results: ' . $query->num_rows();
タダ見つけたさんこう
タダ見つけたさんこう
http://blog.cgfm.jp/garyu/archives/2001こっから引用下記
<?php //カスタム投稿タイプの場合slugを取得 $post_type = get_post_type(); //取得結果: 'event' //カスタム投稿タイプのラベルを取得 $post_type_object = get_post_type_object($post_type); $post_type_label = $post_type_object->label; //取得結果:'イベント情報' //クエリからtaxonomy(カスタム分類タクソノミー)のslug取得 $taxonomy_var = get_query_var('taxonomy'); //取得結果:'event-category' //クエリからterm(カスタム分類タクソノミー内のカテゴリ)のslug取得 $term_var = get_query_var( 'term' ); //取得結果:'workshop' //termの情報を取得 $my_term = get_term_by('slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); //termのラベルを取得 $term_name = $my_term->name; //取得結果:'ワークショップ' ?>
タクソノミーで親には子のカテゴリ、子には商品ページ一覧を
http://ja.forums.wordpress.org/topic/7806
ここ参照
<?php $term = get_term_by('slug',get_query_var( 'term' ),get_query_var( 'taxonomy' ) ); ?> <?php if ( $term->parent ) { // 子? $posts = get_posts( array( 'taxonomy' => get_query_var( 'taxonomy' ), 'term' => get_query_var( 'term' ), ) ); ?><ul><?php foreach ( (array) $posts as $post ) : setup_postdata( $post ); printf('<li><a href="%1$s">%2$s</a></li>', esc_url( get_permalink( get_the_ID() ) ), esc_html( get_the_title( get_the_ID() ) ) ); endforeach; ?></ul><?php wp_reset_postdata(); } else { wp_list_categories( array( 'taxonomy' => get_query_var( 'taxonomy' ), 'child_of' => $term->term_id, 'hide_empty' => 0, ) ); }?>
興味深 関数
$wp_query->get_queried_object();
http://elearn.jp/wpman/function/get_queried_object.html
こいつで色色取得できるらし
http://ja.forums.wordpress.org/topic/6403
こっからいった
タクソノミーページ(アーカイブ)などで
<?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, ) ); }?>