【问题标题】:Remove Title Link for Specific Category in Wordpress删除 Wordpress 中特定类别的标题链接
【发布时间】:2015-04-09 10:07:08
【问题描述】:

我正在运行 Wordpress 4.1。我的网站上有两个博客页面,虽然我并不真正了解 php,但我做了一些修改并想出了如何修改页面模板,以便每个页面只显示特定类别的帖子。那段代码如下所示:

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

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

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

我是一个 HTML/CSS 专家,所以我的深度不够,但如果有办法修改循环来实现这一点,我很想学习如何。提前感谢您的帮助。

【问题讨论】:

    标签: php wordpress hyperlink categories title


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      • 1970-01-01
      • 1970-01-01
      • 2016-01-02
      • 2019-02-06
      • 1970-01-01
      相关资源
      最近更新 更多