PostGallery
13:23 pm
投稿記事から画像だけ抜き出して、ギャラリーにしてしまうPostGalleryを設置しました。
結構、苦労しました。
設置方法は以下の通りです。
1.新規にカテゴリー PostGallery を作ります。
普通に管理画面から作るだけです。
作り終わったらPostGalleryのカテゴリーIDを調べておきます。
2.使っているテーマのindex.phpやcategory.phpからcategory-ID.phpを作ります。
例えば、index.php を適当なエディタで開いて、カテゴリーIDが199だったとすると、
category-199.phpという名前で保存します。
3.category-199.php を修正し保存します。
<?php the_content(); ?>を含む周辺のコード削除し、替わりに以下のコードを埋め込みます。この例では、div id=content 部分を置き換える例です。
<div id="content">
<?php $paged = get_query_var('paged'); ?>
<?php query_posts("category_name=postgallery&posts_per_page=5&paged=$paged"); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="date"><span><?php the_time('M') ?></span> <?php the_time('d') ?></div>
<div class="title">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<div class="postdata">
<span class="category"><?php the_category(', ') ?></span>
</div>
</div>
<div id="gallerypost">
<?php $idno = get_the_id(); ?>
<?php $codex = 'numberposts=-1&post_type=attachment&post_status=inherit&order=ASC&post_parent=' ?>
<?php $codex = $codex .$idno ?>
<?php $myposts = get_posts($codex); ?>
<?php if ($myposts): foreach($myposts as $post):setup_postdata($post); ?>
<a href="<?php the_permalink() ?>" rel="shadowbox"><?php echo wp_get_attachment_image('','thumbnail'); ?></a>
<?php endforeach; endif; ?>
</div><!--/gallerypost -->
<br/>
</div><!--/post -->
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
<?php else : ?>
<h2>Not Found</h2>
<p>Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
</div><!--/content -->4.画像が入ってる投稿のカテゴリーのpostgalleryにチェックを入れます。
サイトのカテゴリーからpostgalleryをクリックするとチェックを入れた投稿内の画像が投稿ごとにサムネールで一覧表示されるようになります。
Related Posts
No Comments »
RSS feed for comments on this post. TrackBack URL
Leave a comment
You must be logged in to post a comment.