Show post type taxonomy

时间:2015-08-09 作者:djhru

我正在制作一个WordPress主题,我已经将“AVENUE”主题的帖子类型代码复制到了“FabThemes”。

代码如下:

<?php 

/* Property Listings*/

function post_type_listings() {
register_post_type(
                    \'listings\', 
                    array( \'public\' => true,
                            \'publicly_queryable\' => true,
                            \'has_archive\' => true, 
                            \'hierarchical\' => false,
                            \'menu_icon\' => get_stylesheet_directory_uri() . \'/images/listing.png\',
                            \'labels\'=>array(
                                        \'name\' => _x(\'Listings\', \'post type general name\'),
                                        \'singular_name\' => _x(\'Listing\', \'post type singular name\'),
                                        \'add_new\' => _x(\'Add New\', \'listing\'),
                                        \'add_new_item\' => __(\'Add New Listing\'),
                                        \'edit_item\' => __(\'Edit Listing\'),
                                        \'new_item\' => __(\'New Listing\'),
                                        \'view_item\' => __(\'View Listing\'),
                                        \'search_items\' => __(\'Search Listings\'),
                                        \'not_found\' =>  __(\'No listings found\'),
                                        \'not_found_in_trash\' => __(\'No Listing found in Trash\'), 
                                        \'parent_item_colon\' => \'\'
                                        ),                           
                            \'show_ui\' => true,
                            \'menu_position\'=>5,
                            \'query_var\' => true,
                            \'rewrite\' => TRUE,
                            \'rewrite\' => array( \'slug\' => \'listing\', \'with_front\' => FALSE,),
                            \'register_meta_box_cb\' => \'mytheme_add_box\',
                            \'supports\' => array(
                                        \'title\',
                                        \'thumbnail\',
                                        \'comments\',
                                        \'editor\'
                                        )
                            ) 
                    );
                } 
add_action(\'init\', \'post_type_listings\');

/* Price range taxonomy */

function create_range_taxonomy() 
{
$labels = array(
                              \'name\' => _x( \'Range\', \'taxonomy general name\' ),
                              \'singular_name\' => _x( \'range\', \'taxonomy singular name\' ),
                              \'search_items\' =>  __( \'Search Range\' ),
                              \'all_items\' => __( \'All Range\' ),
                              \'parent_item\' => __( \'Parent Range\' ),
                              \'parent_item_colon\' => __( \'Parent Range:\' ),
                              \'edit_item\' => __( \'Edit Range\' ), 
                              \'update_item\' => __( \'Update Range\' ),
                              \'add_new_item\' => __( \'Add New Range\' ),
                              \'new_item_name\' => __( \'New Range Name\' ),
);  
register_taxonomy(\'range\',array(\'listings\'), array(
    \'hierarchical\' => true,
    \'labels\' => $labels,
    \'show_ui\' => true,
    \'query_var\' => true,
    \'rewrite\' => array( \'slug\' => \'range\' ),
  ));
}

/* Location Taxonomy */

function create_location_taxonomy() 
{
$labels = array(
                              \'name\' => _x( \'Location\', \'taxonomy general name\' ),
                              \'singular_name\' => _x( \'Location\', \'taxonomy singular name\' ),
                              \'search_items\' =>  __( \'Search Location\' ),
                              \'all_items\' => __( \'All Locations\' ),
                              \'parent_item\' => __( \'Parent Location\' ),
                              \'parent_item_colon\' => __( \'Parent Location:\' ),
                              \'edit_item\' => __( \'Edit Location\' ), 
                              \'update_item\' => __( \'Update Location\' ),
                              \'add_new_item\' => __( \'Add New Location\' ),
                              \'new_item_name\' => __( \'New Location Name\' ),
);  
register_taxonomy(\'location\',array(\'listings\'), array(
    \'hierarchical\' => true,
    \'labels\' => $labels,
    \'show_ui\' => true,
    \'query_var\' => true,
    \'rewrite\' => array( \'slug\' => \'location\' ),
  ));

}

/* Type of property Taxonomy */

function create_property_taxonomy() 
{
$labels = array(
                              \'name\' => _x( \'Property type\', \'taxonomy general name\' ),
                              \'singular_name\' => _x( \'Property type\', \'taxonomy singular name\' ),
                              \'search_items\' =>  __( \'Search Property type\' ),
                              \'all_items\' => __( \'All Property types\' ),
                              \'parent_item\' => __( \'Parent Property type\' ),
                              \'parent_item_colon\' => __( \'Parent Property type\' ),
                              \'edit_item\' => __( \'Edit Property type\' ), 
                              \'update_item\' => __( \'Update Property type\' ),
                              \'add_new_item\' => __( \'Add Property type\' ),
                              \'new_item_name\' => __( \'New Property type\' ),
);  
register_taxonomy(\'property\',array(\'listings\'), array(
    \'hierarchical\' => true,
    \'labels\' => $labels,
    \'show_ui\' => true,
    \'query_var\' => true,
    \'rewrite\' => array( \'slug\' => \'property\' ),
  ));

}

/* Area Taxonomy */

function create_area_taxonomy() 
{
$labels = array(
                              \'name\' => _x( \'Area\', \'taxonomy general name\' ),
                              \'singular_name\' => _x( \'Area\', \'taxonomy singular name\' ),
                              \'search_items\' =>  __( \'Search Areas\' ),
                              \'all_items\' => __( \'All Areas\' ),
                              \'parent_item\' => __( \'Parent Area\' ),
                              \'parent_item_colon\' => __( \'Parent Area\' ),
                              \'edit_item\' => __( \'Edit Area\' ), 
                              \'update_item\' => __( \'Update Area\' ),
                              \'add_new_item\' => __( \'Add Area\' ),
                              \'new_item_name\' => __( \'New Area\' ),
);  
register_taxonomy(\'area\',array(\'listings\'), array(
    \'hierarchical\' => true,
    \'labels\' => $labels,
    \'show_ui\' => true,
    \'query_var\' => true,
    \'rewrite\' => array( \'slug\' => \'area\' ),
  ));

}


/* Listing type Taxonomy */

function create_type_taxonomy() 
{
$labels = array(
                              \'name\' => _x( \'Listing type\', \'taxonomy general name\' ),
                              \'singular_name\' => _x( \'Listing type\', \'taxonomy singular name\' ),
                              \'search_items\' =>  __( \'Search Listing types\' ),
                              \'all_items\' => __( \'All Listing types\' ),
                              \'parent_item\' => __( \'Parent Listing types\' ),
                              \'parent_item_colon\' => __( \'Parent Listing type\' ),
                              \'edit_item\' => __( \'Edit Listing type\' ), 
                              \'update_item\' => __( \'Update Listing type\' ),
                              \'add_new_item\' => __( \'Add Listing type\' ),
                              \'new_item_name\' => __( \'New Listing type\' ),
);  
register_taxonomy(\'type\',array(\'listings\'), array(
    \'hierarchical\' => true,
    \'labels\' => $labels,
    \'show_ui\' => \'radio\',
    \'query_var\' => true,
    \'rewrite\' => array( \'slug\' => \'type\' ),
  ));

}


/* Bedrooms Taxonomy */

function create_bedrooms_taxonomy() 
{
$labels = array(
                              \'name\' => _x( \'Bedrooms\', \'taxonomy general name\' ),
                              \'singular_name\' => _x( \'Bedrooms\', \'taxonomy singular name\' ),
                              \'search_items\' =>  __( \'Search Bedrooms\' ),
                              \'all_items\' => __( \'All Bedrooms\' ),
                              \'parent_item\' => __( \'Parent Bedrooms\' ),
                              \'parent_item_colon\' => __( \'Parent Bedrooms\' ),
                              \'edit_item\' => __( \'Edit Bedrooms\' ), 
                              \'update_item\' => __( \'Update Bedrooms\' ),
                              \'add_new_item\' => __( \'Add Bedrooms\' ),
                              \'new_item_name\' => __( \'New Bedrooms\' ),
);  
register_taxonomy(\'bedrooms\',array(\'listings\'), array(
    \'hierarchical\' => true,
    \'labels\' => $labels,
    \'show_ui\' => true,
    \'query_var\' => true,
    \'rewrite\' => array( \'slug\' => \'bedroom\' ),
  ));

}



add_action( \'init\', \'create_area_taxonomy\', 0 );
add_action( \'init\', \'create_range_taxonomy\', 0 );
add_action( \'init\', \'create_location_taxonomy\', 0 );
add_action( \'init\', \'create_property_taxonomy\', 0 );
add_action( \'init\', \'create_type_taxonomy\', 0 );
add_action( \'init\', \'create_bedrooms_taxonomy\', 0 ); 




/* PRE-DEFINE TERMS */

##Featured##
function add_range_term_featured() {
if(!is_term(\'Featured\', \'type\')){
  wp_insert_term(\'Featured\', \'type\');
}
}

##Reduced#
function add_range_term_reduced() {
if(!is_term(\'Reduced\', \'type\')){
  wp_insert_term(\'Reduced\', \'type\');
}
}

##Sold#
function add_range_term_sold() {
if(!is_term(\'Sold\', \'type\')){
  wp_insert_term(\'Sold\', \'type\');
}
}


add_action( \'init\', \'add_range_term_featured\' );
add_action( \'init\', \'add_range_term_reduced\' );
add_action( \'init\', \'add_range_term_sold\' );





?>
有了这个代码后,除了一个部分外,其他的帖子类型都很好,当我使用搜索框过滤结果时,搜索会起作用,但不会显示任何结果!只需加载索引页!

enter image description here

[![在此输入图像描述][2]][2]

我想知道需要使用什么代码,需要制作什么页面来显示搜索结果?

这里是大道主题的链接。http://www.fabthemes.com/Avenue/

1 个回复
SO网友:Brad Dalton

在中设置公共参数register_post_type 要做到这一点:

public\'             => true,
public(布尔)(可选)控制类型对作者(在\\u nav\\u菜单中显示\\u,显示\\u ui)和读者(从\\u搜索中排除,\\u,可公开查询)可见的方式。

默认值:false

“true”-表示从\\u搜索中排除\\u:false、public\\u queryable、show\\u in\\u nav\\u menu和show\\u ui。内置类型attachment、page和post与此类似。

create a search.php file.

结束

相关推荐

WordPress中Single-{post-type}.php的固定链接结构

我尝试了多种方法将我的自定义帖子类型显示为single-{post-type} 最后,我用过之后,效果很好:\'rewrite\'=> false, 在那之前,我用\'rewrite\' => array( \'slug\' => \'custom-post-type\' ) 但对我来说从来都不管用。不知道我哪里出错了。现在我应该感到很高兴,因为它的工作没有任何错误。但permalink有一点困惑,因为它的显示:localhost/myblog/?news=break