PHP 类别的页面模板(WordPress)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 类别的页面模板(WordPress)相关的知识,希望对你有一定的参考价值。
<?php
//Template Name: Category Listing
/*
This page will grab posts from a category that matches the page title
OR
This page will grab posts from a category that matches the value for the 'category' custom field
*/
$pageID = $post->ID;
$cat = get_post_meta($pageID, 'category',true);
if (empty($cat)) $cat = strtolower($post->post_title);
get_header(); ?>
<div id="content" class="narrowcolumn">
<?php /* below, get the title and any content for the actual page - before we go and get the other posts */ ?>
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2 class="clear"><?php the_title(); ?></h2>
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
</div>
<?php edit_post_link('Edit this entry.', '<p class="clear editLink">', '</p>'); ?>
<?php endwhile; endif; ?>
<?php /* below, change the query to find posts of the specified category */ ?>
<?php $the_query = new WP_Query('category_name='.$cat); ?>
<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<!--<h3 class="clear"><a href="<?php the_permalink($post->ID); ?>"><?php the_title(); ?></a></h3>-->
<h3 class="clear"><?php the_title(); ?></h3>
<div class="entry">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
</div>
<?php edit_post_link('edit this page', '<p class="clear">', '</p>'); ?>
</div>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
以上是关于PHP 类别的页面模板(WordPress)的主要内容,如果未能解决你的问题,请参考以下文章