基本
<!-- インクルード -->
<?php include("header.php"); ?>
<?php include(get_template_directory() . "/8_page_0_page/3_price_tax.php"); //親テーマ ?>
<?php include(get_stylesheet_directory() . "/6_footer/footer_call_css.php"); //子テーマ?>
<!------------------------------------------<br>
/////////////////////////超基本/////////////////////////
---------------------------------->
<?php echo home_url(); //ホームリンク ?>
<?php dynamic_sidebar(2); //サイドバ ?>
<?php the_content(); //コンテンツ?>
<!--リンク付きタイトル-->
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<!------------------------
/////////////////////////投稿日/////////////////////////
------------------------------------>
<!--現在の投稿の公開時刻を表示-->
<?php the_time('Y.m.d'); ?>
<!--同じ日付は1度だけ取得 -->
<?php the_date('Y.m.d'); ?>
<!--必ずループ-->
<?php get_the_date('Y.m.d'); //投稿日だけ取得 ?>
<?php get_the_time('Y.m.d'); //記事の投稿/更新時間をPHPの値として返す。?>
<!--チャートJSには-->
<!--クエリポストで-->
<?php $day = get_the_date('m/d'); ?>
<?php $days[] = $day; ?>
<!--//スプリクと内に-->
<!-- labels : ["<?php echo implode( '","', $days )//区切り文字指定 ?>"], -->
<!--とした。-->
<!---日時基本--->
'Y年m月d日(D)' ⇒ 2009年09月09日(木)
'Y/m/d' ⇒ 2009/09/09
'Y年n月j日(D)' ⇒ 2009年9月9日(木)
'Y/n/j' ⇒ 2009/9/9
'Y年m月d日(D)h時i分s秒'
⇒ 2009年09月09日(木)09時09分09秒
'Y/m/d h:i:s' ⇒ 2009/09/09 09:09:09
シングル・記事ループ にて動作するコード
<!------------ 記事カテゴリ -------------------->
<!--リンクあり-->
<?php the_category(); ?>
<!--リンクなし 1つのみ-->
<?php $cat = get_the_category(); $cat = $cat[0]; { echo $cat->cat_name; } ?>
<!------------ 記事タグ -------------------->
<!--記事タグ リンクあり-->
<?php the_tags('タグ: ', ', '); ?>
<?php the_tags( $before, $sep, $after ); ?>
<?php the_tags( '前', '区切り', '後ろ' ); ?>
<!--記事タグ リンクなし これしかない-->
<?php //タグ名リンク無しで取得
$posttags = get_the_tags(); if ($posttags) {foreach($posttags as $tag) {echo $tag->name . ','; }}
?>
<!------------ 記事ターム -------------------->
<!--//////////////////////get_the_term_list//////////////////////-->
<!--リンクあり--->
<?php echo get_the_term_list( $post->ID, 'jirei1', '<ul><li>', '</li><li>', '</li></ul>' ); ?>
<?php echo get_the_term_list( $post->ID, 'schedule_cat', '<div class="sche_cats">', '</div><div class="sche_cats">', '</div>' ); ?>
<!--//////////////////////gwp_get_object_terms//////////////////////-->
<!--リンクなし--->
<?php $terms = wp_get_object_terms($post->ID,'jirei1'); foreach($terms as $term){echo $term->name . ' ';} ?>
<!--リンクなし 1つのみ--->
<!--春日井ナビのgeoで使ったが いらんくね?--->
<?php
$dd_terms = wp_get_object_terms( $post->ID, 'product' );
if ( !empty( $dd_terms ) ) {
if ( !is_wp_error( $dd_terms ) ) {
echo '<ul class="page_cate_ul>';
$i = 0;
$kiji = 1;
foreach ( $dd_terms as $term ) {
if ( $i >= $kiji ) { //0より多いか等しい
break;
} else {
echo '<li class="catebox"><a href="' . get_term_link( $term->slug, 'product' ) . '">' . esc_html( $term->name ) . '</a></li>';
}
echo '</ul>';
$i++;
}
}
}
?>
<?php //リンクありでクラスをつけて取得 多分ファルで使用
$taxxx = 'schedule_cat';
$dd_terms = wp_get_object_terms( $post->ID, $taxxx );
if ( !empty( $dd_terms ) ) {
if ( !is_wp_error( $dd_terms ) ) {
foreach ( $dd_terms as $term ) {
echo '<div class="sche_cats">';
echo '<a class="f_button" href="' . get_term_link( $term->slug, $taxxx ) . '">' . esc_html( $term->name ) . '</a>';
echo '</div>';
}
}
}
?>
<!--//////////////////////get_the_terms//////////////////////-->
<!--リンクなしもいちょ こちらは ある場合のみと分岐指示-->
<?php
if ( $terms = get_the_terms($post->ID, 'jirei1') ) {
echo ''; //前 <ul>
foreach ( $terms as $term ) {
echo '' . esc_html($term->name) . ''; //"前後ろ<li></li>
}
echo ''; //後ろ</ul>
}
?>
<!--//////////////////////wp_get_post_termsは並び順を指定出来る//////////////////////-->
<?php //ターム名リンク無しで取得
$terms = wp_get_post_terms( $post->ID, 'car_maker_tax' ); //分類で設定した名称
$names = array();
echo ""; //前の文字
foreach ( $terms as $term ) {
$names[] = $term->name;
}
?>
<?php echo implode( ',', $names ); //ターム名区切り文字を指定 ?>
アーカイブにて 動作するコード
<!----★カテゴリー名 ターム名 タグ名を表示-->
<?php single_term_title( ); //アーカイブターム名を出力
?>
アーカイブでは
$term にすでにタームスラッグが入っているの それでよければOK
ターム情報は
taxonomy.phpで現在表示中のターム情報を取得:
get_queried_object(); で取得可能
$my_terms = get_queried_object();
echo $my_terms->name;
<?php
//すべて↑これで出力されるが一応
//カテゴリーアーカイブなら 'single_cat_title( );'
//タグアーカイブなら 'single_tag_title( );'
//タクソノミー(ターム)アーカイブなら 'single_term_title( );'
?>
<!---月刊アーカイブの年と月を表示-->
<?php echo get_query_var('year').'年'.get_query_var('monthnum').'月'; ?>
<!--タクソノミー-->
<?php get_query_var('taxonomy') ?>
<!--ポストタイプ-->
<?php $post_type = get_query_var('post_type'); ?>
http://utsutsunogare.com/get-custom-post-type/
<!--タームのカスタムフィールド 使う-->
<?php //タームのカスタムフィールド 使う
$term_disp = term_description(); //アーカイブでディスプを
//echo $term_disp; // ディスプ出力
//$taxonomy_slugを設置
$taxonomy_slug = get_query_var('taxonomy'); // タクソノミースラッグを取得
//下記なら上書き
if(is_category()){
$taxonomy_slug = 'category'; }//カテゴリはcategory
if(is_tag()){
$taxonomy_slug = 'post_tag'; }//タグはtag
//このようにして、カスタムフィールドを取得できる
$count = get_field( 'views',$taxonomy_slug . '_' . $term_id );
// echo "<pre>";
// print_r($count);
// echo "</pre>";
?>
どこでも動作するコード
<!--wp_list_categories カテゴリ リンクあり 一覧-->
<?php
$args = array(
'show_option_all' => '',
'orderby' => 'name',
'order' => 'ASC',
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => '',
'feed_type' => '',
'feed_image' => '',
'exclude' => '',
'exclude_tree' => '',
'include' => '',
'hierarchical' => 1,
'title_li' => __( 'Categories' ),
'show_option_none' => __( '' ),
'number' => null,
'echo' => 1,
'depth' => 0,
'current_category' => 0,
'pad_counts' => 0,
'taxonomy' => 'category',
'walker' => null
);
wp_list_categories( $args );
?>
<!--
下記2つカテゴリリスト・タームリストに投稿数とスラッグを表示させたい。
それもhref内にビシッと。あわよくばliにスラッグのclassもつけたい。
http://gooodmark.jpn.org/library/269/
-->
<!--カテゴリリスト-->
<ul>
<?php
$categories=get_categories();
foreach($categories as $category) {
echo '<li class="cat-'. $category-> slug .'">';
echo '<a href="' .get_category_link($category->term_id) . '">' .$category->name .'<span class="eng">' .$category->slug .'</span><span class="num">' .$category->count .'</span></a>';
echo '</li>';
} ?>
</ul>
<!--タームリスト-->
<ul>
<?php
$terms = get_terms('タクソノミー名');
foreach ($terms as $term ) {
$des_list .= '<li class="des-'. $term-> slug .'">';
$des_list .= '<a href="' . get_term_link( $term ) . '">';
$des_list .= $term->name . '<span class="eng">' .$term->slug .'</span><span class="num">' .$term->count .'</span></a></li>';
}
echo $des_list; ?>
</ul>
<!--////////////////////
上記ではカレントカテゴリがでない、また複数使う場合の参考
////////////////////-->
<ul class="li_menu_ul">
<?php
$terms = get_terms('schedule_year');
foreach ($terms as $term ) {
//カレントカテのために追加
$term_id = $term->term_id;//現在のタームID
$taxonomy_name = get_query_var('taxonomy');//現在のタクソノミー名
$current_calss = '';//カレント用に
if(is_tax($taxonomy_name , $term_id))://なら
$current_calss = ' current-cat';
endif;//おわり
$des_list .= '<li class="des-'. $term-> slug . $current_calss .'">';
$des_list .= '<a href="' . get_term_link( $term ) . '" class="f_button">';
$des_list .= $term->name . '</a></li>';
}
echo $des_list;
?>
</ul>
<ul class="li_menu_ul">
<?php
$terms = get_terms('schedule_cat');
foreach ($terms as $term ) {
//カレントカテのために追加
$term_id = $term->term_id;//現在のタームID
$taxonomy_name = get_query_var('taxonomy');//現在のタクソノミー名
$current_calss = '';//カレント空に
if(is_tax($taxonomy_name , $term_id))://なら
$current_calss = ' current-cat';
endif;//おわり
$des_list2 .= '<li class="des-'. $term-> slug . $current_calss .'">';
$des_list2 .= '<a href="' . get_term_link( $term ) . '" class="f_button">';
$des_list2 .= $term->name . '</a></li>';
}
echo $des_list2; ?>
</ul>