我的网站上有三个页面。我们称它们为 home、page2 和 page3。我的“主页”设置为静态首页。我的“page2”设置为博客页面。
我想要的是以下内容:
我希望 page2 显示具有特定类别(其中 ID 已知)的博客文章。
和
我希望 page3 显示具有特定类别(其 ID 已知)的博客文章。
仅显示具有特定类别的帖子(或者实际上在我的情况下,显示不包括两个类别的帖子)的 PHP 代码如下:
<?php query_posts($query_string . '&cat=-3,-8'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h3>
<?php the_excerpt('Read the rest of this entry »'); ?>
</div><!-- /.post-->
现在,在我的 page.php 中,我有以下代码来显示一个类别的帖子:
<?php
// BEGIN IF PAGE is newspaper articles page
if ( is_page('newspaper') ) {
//BEGIN POST REGION
query_posts($query_string . '&cat=8'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><?php the_title(); ?></h3>
<?php the_content('Read more »'); ?>
</div><!-- /.post-->
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php
} //end if is_page
?>
但它没有在报纸页面(或这个问题中的第 3 页)上显示正确的帖子。但是,它确实适用于文章页面(主 index.php 博客页面)。
编辑:我也尝试了以下方法(但它不起作用)。我把它放在 index.php 文件中:
<?php
if ( is_page('newspaper') || is_home() ) { // START if is home
?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink() ?>" rel="bookmark"
title="Permanent Link to
<?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h3>
<!--<p><?php the_time('F jS, Y') ?> <?php //the_author() ?></p>-->
<?php the_excerpt('Read the rest of this entry »'); ?>
</div><!-- /.post-->
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php
} //end if is_home() or is_page()
?>
同样,这会在主博客页面上显示帖子,但不会在报纸页面上显示任何帖子......
因此,问题很简单(我认为)。我如何在博客主页面以外的其他页面上显示帖子?
谢谢!阿米特