Tag: サイドバー


wordpress|カスタム投稿のタームタイトルの一覧表示

2017年01月08日 wordpressカスタム投稿テンプレートタグ

サイドバーに特定タームの記事一覧を表示

<?php
$args = array(
'post_type' => 'タイプ名',
'taxonomy' => 'タクソノミー名',
'term' => 'ターム名',
'posts_per_page' => 10,
'numberposts' => '-1', //表示する記事数。-1 ならすべての投稿を取得。
);
$my_posts = get_posts($args);
foreach ( $my_posts as $post ) {
setup_postdata($post); ?>
<li class="icon"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php
}
?>

 

シンプルなターム一覧

<?php wp_list_categories(array('taxonomy' => 'タクソノミー名')); ?>
<?php wp_list_categories(array('title_li' => '', 'taxonomy' => 'タクソノミー名')); ?>

記事の件数を表示する場合

<?php wp_list_categories(array('taxonomy' => 'architect','show_count' => 1)); ?>

 

特定タームの一覧表示

<?php wp_list_categories(array('title_li' => '', 'taxonomy' => 'カスタム分類名')); ?>

 

 

複数のサイドバーテンプレートを表示する方法

2014年09月09日 wordpressテンプレートタグ

1.「sidebar-●●●.php」というファイルを作成

2.テンプレート内に以下を入力

<?php get_sidebar(‘●●●‘); ?>

 

ウィジットスペース追加

2012年12月21日 wordpressテンプレートタグ

function.php

<?php

if ( function_exists(‘register_sidebar’) )
register_sidebar(array(
‘name’=>’Left-side’,
‘before_widget’ => ‘<div>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h2>’,
‘after_title’ => ‘</h2>’,
));


/** 以下を追加 */
register_sidebar(array(
‘name’=>’名前’,
‘before_widget’ => ‘<div>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h2>’,
‘after_title’ => ‘</h2>’,
));

?>

ウィジェットを出力

【テンプレートに追加コード】

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('2')) : ?>
<!-- ウィジェットが設定されていない場合の出力をここに記述します -->
<?php endif; ?>