Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have to create a website with a part concerning houses, grouped by type.

I thought of using custom post type "house" and custom taxonomy "house_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 );

i've created

some house type (type1, type2...)
- some houses to which i have attributed a house type

house 1 => type1
house 2 => type1
house 3 => type2
house 4 => type3
house 5 => type1

What i need to have (what my client wants) A menu like this :

-Home
- Houses & Services -type1 => list of all type1 houses
                    -type2 => list of all type2 houses
                    -type3 => list of all type2 houses
- Other menu...

When i'm a house page, i need to have in the sidebar, the link of all the other houses of the same type. For instance : if i am in House1, i want to display the links of "Type1 house" => house1, house2, house 5

I've created as many pages as house type with a template :

<?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(); ?>

If i put theses specific pages in the menu, i've got the right lists. BUT i have several problems :

1) I have to create as many templates as house type (because of the taxonomy filter 'house_type' => 'type1' in the previous example. => Is there a way to avoid this, to achieve my goal ?

2) When i'm on the house page, how to display the links of the house with the same house type ? I've tried get_taxonomies, get taxonomy, wp list categories, but this doesn't seem to retrieve the information i need (or i cant see how).

3) The client wants a breadcrumb. But this structure (custom post called in a page template) messes with the breadcrumb : Instead of having

Home > Houses & Services > Type1

i have

Home > houses (the custom type name) > house1

I've tried several breadcrumb plugins but they all fail to display the correct path. has anybody used this kind of structure with a working breadcrumb ?

Thanks in advance

share|improve this question

1 Answer 1

up vote 1 down vote accepted

For question 1, use a custom field when you create the page and use the same template each time. Here is an example using a custom field named house_type.

<?php

// Template Name: House Type

[ ... ]

$house_type = get_post_meta( get_queried_object_id(), 'house_type', true );

$args = array (
    'post_type'     => 'house',
    'orderby'       => 'meta_value',
    'house_type'    => $house_type,
    'order'         => 'DESC',
    'posts_per_page'=> -1,
);

Ask the other two questions as two separate new questions. It is easier to find 3 people who can answer one question each than it is to find one person that can answer all 3 questions.

share|improve this answer
    
You're right. Thanks for the answer. I knew this could be a bad idea to give all the questions in one post, but i've been afraid to repeat all the same thing many times in many posts. And many links to other post in a question can be demotivating for the reader. –  user29296 Jun 3 '13 at 7:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.