WordPress页面教程:分类页(category.php)
一、页面简介
显示分类页的页面(相当于栏目页)
二、页面参数
- get_header
- get_the_category
- function_exists
- have_posts
- the_post
- get_the_date
- the_permalink
- the_title
- wp_get_attachment_url
- get_post_thumbnail_id
- get_the_ID
- get_the_title
- esc_url
- the_tags
- the_excerpt
- previous_posts_link
- next_posts_link
- get_sidebar
- get_footer
- single_cat_title
- category_description
- bloginfo
- the_time
- comments_popup_link
- mb_strimwidth
- wp_tag_cloud
- get_option
三、页面案例
(一)、案例
<?php
/**
* The category archive template file.
* @package WordPress
* @subpackage VisitPress
* @since VisitPress 1.0
*/
get_header(); ?>
<div id="wrapper-main">
<div id="container">
<div id="content">
<div class="content-inside">
<?php visitpress_get_breadcrumb(); ?>
<?php if ( get_header_image() != '' ) { ?>
<div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div>
<?php } ?>
<?php if ( have_posts() ) : ?>
<h1 class="archive-title"><?php single_cat_title(); ?></h1>
<?php if ( category_description() ) : ?>
<div class="archive-meta"><?php echo category_description(); ?></div>
<?php endif; ?>
<?php $args = array(
'post_type' => 'post',
'post_status' => 'publish'
);
$query = new WP_Query( $args );
while (have_posts()) : the_post(); ?>
<?php get_template_part( 'content' ); ?>
<?php endwhile; endif; ?>
<?php visitpress_content_nav( 'nav-below' ); ?>
</div><!-- end of content-inside -->
</div><!-- end of content -->
<?php get_sidebar(); ?>
</div><!-- end of container -->
</div><!-- end of wrapper-main -->
<?php get_footer(); ?>
(二)、案例
<?php global $theme; get_header(); ?>
<div id="main">
<?php $theme->hook('main_before'); ?>
<div id="content">
<?php $theme->hook('content_before'); ?>
<h2 class="page-title"><?php printf( __( 'Category Archives: <span>%s</span>', 'themater' ), single_cat_title( '', false ) ); ?></h2>
<?php
if (have_posts()) : while (have_posts()) : the_post();
/**
* The default post formatting from the post.php template file will be used.
* If you want to customize the post formatting for your category pages:
*
* - Create a new file: post-category.php
* - Copy/Paste the content of post.php to post-category.php
* - Edit and customize the post-category.php file for your needs.
*
* Learn more about the get_template_part() function: http://codex.wordpress.org/Function_Reference/get_template_part
*/
get_template_part('post', 'category');
endwhile;
else :
get_template_part('post', 'noresults');
endif;
get_template_part('navigation');
?>
<?php $theme->hook('content_after'); ?>
</div><!-- #content -->
<?php get_sidebars(); ?>
<?php $theme->hook('main_after'); ?>
</div><!-- #main -->
<?php get_footer(); ?>
(三)、案例
<?php
/**
* The category archive template file.
* @package ShootingStar
* @since ShootingStar 1.0.0
*/
get_header(); ?>
<?php if ( have_posts() ) : ?>
<div class="post-loop">
<div class="entry-headline-wrapper">
<div class="entry-headline-wrapper-inner">
<h1 class="entry-headline"><?php single_cat_title(); ?></h1>
<?php shootingstar_get_breadcrumb(); ?>
</div>
</div>
<?php if ( category_description() ) : ?>
<div class="entry-content">
<div class="entry-content-inner">
<div class="category-description"><?php echo category_description(); ?></div>
</div>
</div>
<?php endif; ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part( 'content', 'archives' ); ?>
<?php endwhile; endif; ?>
<?php shootingstar_content_nav( 'nav-below' ); ?>
</div>
</div> <!-- end of content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
(四)、案例
<?php
/**
* The template for displaying Category pages
*
* @package Ribosome
*/
get_header(); ?>
<section id="primary" class="site-content">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
<header class="archive-header">
<h1 class="archive-title"><?php printf( __( 'Category Archives: %s', 'ribosome' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>
<?php if ( category_description() ) : // Show an optional category description ?>
<div class="archive-meta"><?php echo category_description(); ?></div>
<?php endif; ?>
</header><!-- .archive-header -->
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
ribosome_content_nav( 'nav-below' );
?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</section><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
(五)、案例
<?php
/**
* The category archive template file.
* @package LiveRide
* @since LiveRide 1.0.0
*/
get_header(); ?>
<?php if ( have_posts() ) : ?>
<div id="headline-wrapper">
<h1 class="content-headline"><?php single_cat_title(); ?></h1>
</div>
<?php liveride_get_breadcrumb(); ?>
<div id="main-content">
<div id="content">
<?php if ( category_description() ) : ?>
<div class="archive-meta"><?php echo category_description(); ?></div>
<?php endif; ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part( 'content', 'archives' ); ?>
<?php endwhile; endif; ?>
<?php liveride_content_nav( 'nav-below' ); ?>
</div> <!-- end of content -->
<?php get_sidebar(); ?>
</div> <!-- end of main-content -->
<?php get_footer(); ?>
(六)、案例
<?php
/**
* The category archive template file.
* @package MaidenHair
* @since MaidenHair 1.0.0
*/
get_header(); ?>
<?php if ( have_posts() ) : ?>
<div class="content-headline">
<h1 class="entry-headline"><span class="entry-headline-text"><?php single_cat_title(); ?></span></h1>
<?php maidenhair_get_breadcrumb(); ?>
</div>
<?php if ( category_description() ) : ?>
<div class="archive-meta"><?php echo category_description(); ?></div>
<?php endif; ?>
<div<?php if ($maidenhair_post_entry_format != 'One Column') { ?> class="js-masonry"<?php } ?>>
<?php while (have_posts()) : the_post(); ?>
<?php if ($maidenhair_post_entry_format != 'One Column') {
get_template_part( 'content', 'grid' ); } else {
get_template_part( 'content', 'archives' ); } ?>
<?php endwhile; endif; ?>
</div>
<?php maidenhair_content_nav( 'nav-below' ); ?>
</div> <!-- end of content -->
<?php if ($maidenhair_display_sidebar_archives == 'Display') { ?>
<?php get_sidebar(); ?>
<?php } ?>
<?php get_footer(); ?>
THE END