WordPress:基于自定义帖子类型的分类归档

问题描述:

我已经生成了三种不同的自定义帖子类型(例如书籍,电影,游戏)。 而且我对它们都有一个自定义分类(例如流派)。WordPress:基于自定义帖子类型的分类归档

我需要的是基于帖子类型的taxanomy档案。 例如:“书籍类型”,“电影风格”...

有没有解决方案可以做到这一点?现在我只有“流派”的分类归档。

+0

所以,你希望所有的分类存档有三个部分(书籍,电影,游戏)。 – staypuftman

+0

不完全。这就是我已经完成的。我想为每个帖子类型分类存档。例如:只有科幻书。我想拥有这些档案的自己的网址,例如:/ book-genre/science-fiction/ – Cray

+0

好吧,那么你只需要自定义帖子类型的档案与永久链接修改。这真的是一个两部分问题:你需要帮助设置自定义的帖子类型档案或帮助设置永久链接结构? – staypuftman

我喜欢处理自定义文章归档的方式是在WP_Query部分创建一个自定义归档模板,我需要它们。您可以在archive-cptnamehere.php的主题根目录下创建空白文件。

你可能有一些模板谐音加在,但页面的核心是这样的:

<?php 
    // 1- Get ID of the page's path by URL (reliable) 
    $pagePath = $_SERVER['REQUEST_URI']; 
    $pageObject = get_page_by_path($pagePath); 
    $pagePathID = $pageObject->ID; 

    // 2- Print page title 
    $teamPageTitle = get_the_title($pagePathID); 
    echo $teamPageTitle; 

    // 3 - Do a query that gets the data you need 
    // Args: -1 shows all locations, orders locations alphabetically by title, orders locations a-z, only query against team items 
    $args = array(
     'posts_per_page' => -1, 
     'orderby' => 'title', 
     'order' => 'ASC', 
     'post_type' => 'team', 
     'meta_query' => array(
     array(
     'key'   => 'team_page_categorization', 
     'value'  => $team_page_categorization_options_array_item, 
     'compare' => 'LIKE' 
     ) 
    ) 
    ); 
    $the_query = new WP_Query($args); 

    // 4- Setup query while loop 
    if($the_query->have_posts()) { 
     while($the_query->have_posts()) { 
     $the_query->the_post(); 

     // 5- Do what you need to inside the loop 


     // 6- Close it all up, don't forget to reset_postdata so you can do additional queries if necessary!  
     } 
    wp_reset_postdata(); 
    } 
    ?> 
+0

谢谢!但是我已经用自定义页面模板上的自定义查询解决了这个问题。我现在的问题是仅基于自定义帖子类型的分类归档 – Cray

+0

分类归档不能像那样工作。如果它是使用特定分类术语标记的自定义帖子类型的存档,则需要使用上面在CPT存档中显示的循环。 – staypuftman

+0

好的谢谢。但是如何链接到一个分类标准呢? – Cray