删除Wordpress中特定类别的标题链接


Remove Title Link for Specific Category in Wordpress

我正在运行Wordpress 4.1。我的网站上有两个博客页面,虽然我真的不知道php,但我做了一些修补,并想出了如何修改页面模板,使每个页面只显示特定类别的帖子。这段代码看起来像这样:

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

这很好。页面A显示类别1中的帖子,页面B显示类别2中的帖子。

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

我是一个HTML/CSS的家伙,所以在这里真的超出了我的深度,但如果有一种方法可以修改循环来实现这一点,我很想学习如何做到。提前感谢您的帮助。

是的,您可以使用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;
?>