2015-02-09 46 views
0

我正在运行Wordpress 4.1。我在我的网站上有两个博客页面,尽管我并不真正了解php,但我已经做了一些修改,并想出如何修改页面模板,以便每个页面仅显示特定类别的帖子。这段代码看起来像这样:删除Wordpress中特定类别的标题链接

<?php query_posts('cat=2'); ?> 

这工作正常。页面A显示来自类别1的帖子,而页面B显示来自类别2的帖子。

我想要做的是禁用某个特定类别的帖子标题链接。换句话说,页面A将显示来自类别1的帖子(带有标准可点击的标题链接),而页面B将显示来自类别2的帖子(具有不可点击的标题链接)。

我是一个HTML/CSS的人,真的超出了我的深度,但如果有办法修改循环来实现这一点,我很乐意学习如何。预先感谢您的帮助。

回答

0

是的,你可以使用category.php主题文件来做到这一点。当这个页面被击中时,它会加载请求的特定类别以及属于该类别的帖子。

你的主题和循环可能是这个样子:

<?php single_cat_title(); ?> 
<?php echo category_description(); ?> 
if (have_posts()) : while (have_posts()) : the_post(); 
/// display posts from specific category 
endwhile; endif; 

或者,如果你不想使用的是专为该页,您可以创建自己的循环:

query_posts(array ('category_name' => 'my-category-slug', 'posts_per_page' => 50)); 

全部像这样:

<?php 
/* retrieve unlimited # of posts with an category slug of music */ 

query_posts( array ('category_name' => 'music', 'posts_per_page' => -1) ); 

// set $more to 0 in order to only get the first part of the post 
global $more; 
$more = 0; 

// the Loop 
while (have_posts()) : the_post(); 
    the_content('Read the full post »'); 
endwhile; 
?>