目次
トップを固定ページにするテンプレート
Manablog Copyのトップページを固定ページにしてサイト型のブログにしました。
トップページを固定ページにするためにfront-page.phpを作成しました。
Manablog Copyのブログのfront-page.phpを紹介します。
トップページ用のテンプレートを作成
トップページ用のfront-page.phpを作成しました。
トップの固定ページは何も書いていなく空白のままです。
front-page.phpのソース
下記はサムネイル画像に順位を表示してないタイプです。
CSSの調整が必要になるかもしれません。
<?php get_header(); ?>
<?php
global $post;
$args = array( 'posts_per_page' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) {
setup_postdata($post);
?>
<div class="col-xs-12 wrap">
<center>
<h2 style="padding-top: 0px;">新着記事</h2>
</center>
<?php get_template_part( 'meta' ); ?>
<!-- タイトル表示 -->
<h2 class="title" itemprop="name headline">
<a href="<?php the_permalink(); ?>" title="<?php printf(the_title_attribute('echo=0') ); ?>" itemprop="url"><?php the_title(); ?></a>
</h2>
<!-- サムネイルの表示 -->
<div class="front-img" itemprop="image" itemscope itemtype='http://schema.org/ImageObject' class="thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php printf(the_title_attribute('echo=0') ); ?>" itemprop="url"><?php the_post_thumbnail('index_thumbnail'); ?></a>
</div>
<!-- ディスクリプションの表示 -->
<p itemprop="description" class="description">
<?php echo mblog_meta_description(); ?>
</p>
<div class="front">
<div class="readmore"><a href="/new/">新着記事一覧</a></div>
</div>
</div>
<?php
}
wp_reset_postdata();
?>
<div class="col-xs-12 wrap">
<center>
<h2 style="padding-top: 30px;">よく読まれている記事</h2>
</center>
<?php query_posts('meta_key=post_views_count&orderby=meta_value_num&posts_per_page=10&order=DESC');
while(have_posts()) : the_post();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' );
if ( !empty($thumb['0']) ) {
$url = $thumb['0'];
} else {
$url = get_template_directory_uri() . "/images/no-image.png";
}
?>
<div class="col-xs-12 wrap">
<!-- タイトル表示 -->
<h2 class="title" itemprop="name headline">
<a href="<?php the_permalink(); ?>" title="<?php printf(the_title_attribute('echo=0') ); ?>" itemprop="url"><?php the_title(); ?></a>
</h2>
<!-- サムネイルの表示 -->
<div class="front-img" itemprop="image" itemscope itemtype='http://schema.org/ImageObject' class="thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php printf(the_title_attribute('echo=0') ); ?>" itemprop="url"><?php the_post_thumbnail('index_thumbnail'); ?></a>
</div>
<!-- ディスクリプションの表示 -->
<p itemprop="description" class="description">
<?php echo mblog_meta_description(); ?>
</p>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
<div class="col-xs-12 wrap">
</div>
<?php get_footer(); ?>
※この記事のあともカスタマイズするので記事を書いた時点のものです。
閲覧回数を表示するタグ
サムネイル画像に順位を表示し記事の閲覧回数を表示しています。
閲覧回数を表示したところに下記を貼ってください。
<?php echo getPostViews(get_the_ID()); ?>
パンくずリストを修正
トップページを固定ページにするとパンくずリストが表示されます。
気になったので修正しました。
<!-- パンくずリスト -->
<?php wp_reset_query(); ?>
<?php if ( !is_front_page() && !is_home() && !is_category() && !is_tag() && !is_search() ) { ?>
<?php get_template_part( 'breadcrumb' ); ?>
<?php } else { ?>
<?php } ?>
<!-- /パンくずリスト -->