【发布时间】:2011-01-18 16:19:32
【问题描述】:
我从 Wordpress codex 中获取了this code,它以帖子格式显示当前页面的子页面。
我创建了一个名为 "Home" 的页面,并为其分配了一个名为 Front Page 的模板:
front-page.php:
<?php
/**
* Template Name: Front Page
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
get_header(); ?>
<div id="intro">
<div id="tagline">
<?php // Retrieve a list of latest posts or post(s) matching criteria).
$args = array('category_name' => 'Tagline', 'numberposts' => 1, 'order' => 'DESC');
$customposts = get_posts($args);
foreach($customposts as $post) : setup_postdata($post); ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php endforeach; ?>
</div><!-- #tagline -->
<div id="featured">
<img src="<?php bloginfo('template_directory'); ?>/images/<?php echo get_option(THEME_PREFIX . 'intro_image'); ?>" />
</div>
</div><!-- #intro -->
<div id="main-content">
<div id="main-content-first">
<?php // Retrieve a list of latest posts or post(s) matching criteria).
$args = array('category_name' => 'Main Content First');
$customposts = get_posts($args);
foreach($customposts as $post) : setup_postdata($post); ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php endforeach; ?>
</div>
<div id="main-content-middle">
<?php // Retrieve a list of latest posts or post(s) matching criteria).
$args = array('category_name' => 'Main Content Middle');
$customposts = get_posts($args);
foreach($customposts as $post) : setup_postdata($post); ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php endforeach; ?>
</div>
<div id="main-content-last">
<?php // Retrieve a list of latest posts or post(s) matching criteria).
$args = array('category_name' => 'Main Content Last');
$customposts = get_posts($args);
foreach($customposts as $post) : setup_postdata($post); ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php endforeach; ?>
</div>
</div><!-- #main-content -->
<?php
$mypages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
$count = 0;
foreach($mypages as $page)
{
$content = $page->post_content;
if(!$content)
continue;
if($count >= 2)
break;
$count++;
$content = apply_filters('the_content', $content);
?>
<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
<div class="entry"><?php echo $content ?></div>
<?php
}
?>
<?php get_footer(); ?>
然后我将 关于 页面设为子页面(主页的子页面)。
由于某种原因,没有显示任何内容(见模板底部)
有什么建议吗?
【问题讨论】:
标签: wordpress