duanchendu69495 2017-01-10 11:33
浏览 22

在WordPress中使用相同URL结构的分类法下添加页面

I am attempting to create some posts to display on a CPT taxonomy page which follow the same URL structure.

I have a post type of animal and taxonomy of animal-category, the generated URLs for these pages are:

  • domain.com/animal
  • domain.com/animal-category

I then want to create a standard page (not part of this post type) which will have the URL:

  • domain.com/animal-category/page-name

Structurally the page is unrelated to the animal posts and could be a standard page or in a post type, it doesn't matter.

After research and previous knowledge I cannot find a rewrite rule to force a page to use domain.com/animal-category before the page-name is added - as it has already been rewritten for the taxonomy.

Maybe there is a completely different solution to achieve having a page (with this URL structure) on a taxonomy listing?

  • 写回答

2条回答 默认 最新

  • douyuanqia665858 2017-01-10 12:25
    关注

    You can totally do that :)

    1) In your theme create the animal-taxonomy template and name it taxonomy-animal-category.php

    2) In the loop apply a condition to get the displayed item (queried object) as follows:

    <?php $queried_slug =  get_queried_object()->slug;
    
    if($queried_slug=="page-name"){ //IT IS THE PAGE we have
    
    
    }else{ ?>
    <?php if ( have_posts() ) : ?>
    
    
            <?php
            // Start the Loop.
            while ( have_posts() ) : the_post();
    
            // End the loop.
            endwhile;
        else :
    
             echo "NO animals found :)";
    
        endif;
    <?php } ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000