我必须创建一个关于房屋的网站,按类型分组。
我曾想过使用自定义post类型“house”和自定义分类法“house\\u type”。
function custom_post_house() {
$labels = array(
\'name\' => __(\'house\'),
\'add_new\' => \'Add new house\',
\'add_new_item\' => \'Add new house\',
\'edit_item\' => \'Update house\',
\'menu_name\' => __(\'house\')
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'show_in_nav_menus\' => true,
\'menu_position\' => 5,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'with_front\' => true,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'excerpt\'),
\'has_archive\' => false,
);
register_post_type( \'house\', $args );
}
add_action( \'init\', \'custom_post_house\' );
function taxonomies_house() {
$args = array(
\'hierarchical\' => false,
\'label\' => \'House type\',
\'query_var\' => true,
\'rewrite\' => true,
\'show_admin_column\' => true ,
);
register_taxonomy( \'house_type\', \'house\', $args);
}
add_action( \'init\', \'taxonomies_house\', 0 );
我已经创建了
一些房屋类型(类型1、类型2…)
-我认为属于某一房屋类型的一些房屋
house 1 => type1
house 2 => type1
house 3 => type2
house 4 => type3
house 5 => type1
我需要(我的客户想要的)这样的菜单:
-Home
- Houses & Services -type1 => list of all type1 houses
-type2 => list of all type2 houses
-type3 => list of all type2 houses
- Other menu...
当我是一个房屋页面时,我需要在侧栏中有相同类型的所有其他房屋的链接。例如:如果我在House1,我想显示“Type1 house”=>House1、house2、House5的链接
我使用模板创建了与house type一样多的页面:
<?php
/**
* Template Name: House type 1
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php
wp_reset_postdata();
$args = array (
\'post_type\' => \'house\',
\'orderby\' => \'meta_value\',
\'house_type\' => \'type1\', //specific to a house type
\'order\' => \'DESC\',
\'posts_per_page\'=>\'-1\'
);
$query = new WP_Query($args);
$i=0;
echo \'<ul>\';
while ( $query->have_posts() ) : $query->the_post();
?>
<li><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Read %s\', \'twentyeleven\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark">
<div class="thumb"><?php the_post_thumbnail(\'medium\'); ?></div>
<h2 class="titleoverlay"><?php the_title(); ?></h2></a></li>
<?php
$i++;
endwhile;
echo \'</ul>\';
?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
如果我把这些特定的页面放在菜单中,我就得到了正确的列表。但我有几个问题:
(1)I have to create as many templates as house type (由于上一个示例中的分类过滤器“house\\u type”=>“type1”。=>是否有办法避免这种情况,以实现我的目标?
(2)When i\'m on the house page, how to display the links of the house with the same house type ? 我尝试了get\\u分类法、get分类法、wp列表类别,但这似乎无法检索到我需要的信息(或者我看不到如何检索)。
3) 客户想要面包屑。但这种结构(在页面模板中调用的自定义帖子)会弄乱面包屑:而不是
Home > Houses & Services > Type1
我有
Home > houses (the custom type name) > house1
我尝试了几个面包屑插件,但它们都无法显示正确的路径。
has anybody used this kind of structure with a working breadcrumb ?提前感谢