ホームページ制作 | ウェブスタジオ タブレ » tecnicalnote

tecnicalnote
CSSやワードプレスの備忘録です。
カテゴリーページでカテゴリー毎に表示件数を変える
<?php
global $query_string;
$paged = get_query_var('paged');
$catinfo = get_the_category();$catname = $catinfo[0]->category_nicename;
//カテゴリ4は5件まで、それ以外は10件
$cat == '4' ? query_posts($query_string . '&posts_per_page=5')
: query_posts($query_string . '&posts_per_page=5');
if (have_posts()) : while (have_posts()) : the_post();
?>
<a href="<?php the_permalink() ?>"><h3><?php the_title(); ?></h3></a>
<?php the_content(); ?>
<?php endwhile; endif; ?>
で
とりあえず入れるプラグイン
管理上必須
- all-in-one-seo-pack
SEO必須 - wp-db-backup
バックアップ - duplicate-post
記事コピー - order-categories
カテゴリ並べ替え - google-xml-sitemaps-with-multisite-support
サイトマップ - maintenance-mode
メンテナンスモード - Secure WordPress
セキュリティ強化
内容により
- breadcrumb-navxt
パンくず - inquiry-form-creator
フォーム(DB機能付き) - fancy-box
LightBox風画像ビュアー - paged-gallery
ギャラリーのページ分け - limit-post-ja
投稿文字数指定表示 - category-icons
カテゴリをアイコン表示 - category-limitation
アカウントで管理できるカテゴリを限定 - popular-posts-plugin
人気記事表示 - post-plugin-library
popular-posts-pluginを使う時に必要 - ktai-style
ガラゲー - wptouch
スマホ
カテゴリーテンプレート
カテゴリーページの表示件数を指定する場合
<?php
global $query_string;
// ページナビを使う場合
$paged = get_query_var('paged');
$catinfo = get_the_category();$catname = $catinfo[0]->category_nicename;
// カテゴリが2を2件まで、それ以外は5件
$cat == '2' ? query_posts($query_string . '&posts_per_page=2')
: query_posts($query_string . '&posts_per_page=5');
if (have_posts()) : while (have_posts()) : the_post();
?>
ページナビ
<div class="tablenav"><?php global $wp_rewrite;
$paginate_base = get_pagenum_link(1);
if (strpos($paginate_base, '?') || ! $wp_rewrite->using_permalinks()) {
$paginate_format = '';
$paginate_base = add_query_arg('paged', '%#%');
} else {
$paginate_format = (substr($paginate_base, -1 ,1) == '/' ? '' : '/') .
user_trailingslashit('page/%#%/', 'paged');;
$paginate_base .= '%_%';
}
echo paginate_links( array(
'base' => $paginate_base,
'format' => $paginate_format,
'total' => $wp_query->max_num_pages,
'mid_size' => 5,
'current' => ($paged ? $paged : 1),
)); ?></div>
CSS
.tablenav {
color: #2583ad;
padding:10px;
line-height:2em;
text-align:center;
}
a.page-numbers, .tablenav .current {
color: #00019b;
padding: 2px .4em;
border:solid 1px #ccc;
text-decoration:none;
font-size:smaller;
}
a.page-numbers:hover {
color:white;
background: #328ab2;
}
.tablenav .current {
color: white;
background: #328ab2;
border-color: #328ab2;
font-weight:bold:
}
.tablenav .next, .tablenav .prev {
border:0 none;
background:transparent;
text-decoration:underline;
font-size:smaller;
font-weight:bold;
}
ページナビがうまく動かない(NotFoundか同じページが表示される)場合は
ワードプレスの設定、表示設定の「1ページに表示する最大投稿数」を
最小単位に設定する
で。
記事に投稿された画像のみを並べて表示
記事本文を表示しないで記事に投稿された画像のみを並べて表示する場合
<?php query_posts('cat=○&showposts=○'); ?>
<ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
$files = get_children("post_parent=$id&post_type=attachment&post_mime_type=image");
if (empty($files)){
//画像がない場合
print '<a href="'.get_permalink().'" title="'.$post->post_title.'">
<img src="#" alt="" width="100" height="100"></a>
<a href="'.get_permalink().'" title="'.$post->post_title.'">'.the_title_attribute("echo=0").'</a>';
}else{
//画像がある場合
$keys = array_keys($files);
$num=$keys[0];
$thumb=wp_get_attachment_image($num,array(100,100));
print '<li>';
print '<a href="'.get_permalink().'" title="'.$post->post_title.'">';
print $thumb;
//記事タイトルを表示
print '</a><a href="'.get_permalink().'" title="'.$post->post_title.'">'.the_title_attribute("echo=0");
print '</a>';
print '</li>';
}
?>
<?php endwhile;else: ?>
</ul>
<?php endif;wp_reset_query(); ?>
で。
カテゴリ直下の記事のみ表示(子カテゴリ含まず)
カテゴリ直下の記事のみ表示(子カテゴリ含まず)
<?php query_posts( array( 'category__in' => array( ※ ) ) ); ?> <?php while (have_posts()) : the_post(); ?> <li class="cat-item"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> <?php wp_reset_query(); ?>
※にカテゴリ番号
で。






