我无法解决这个问题。
我需要完成的任务: 在this page我需要在“新发展”的自定义分类下显示标有“Doral”一词的项目的结果,这是自定义帖子类型“列表”的一部分。
目前,该页面显示所有项目,无论自定义帖子类型“列表”的术语或分类如何。
我目前拥有的内容: 我的自定义分类法创建代码
add_action('init', 'property_new_dev_taxonomies');
function property_new_dev_taxonomies() {
register_taxonomy('new-developments',
'listing',
array (
'labels' => array (
'name' => 'New Developments',
'singluar_name' => 'New Developments',
'search_items' => 'Search New Developments',
'popular_items' => 'Popular New Developments',
'all_items' => 'All New Developments',
'parent_item' => 'Parent New Development',
'parent_item_colon' => 'Parent New Development:',
'edit_item' => 'Edit New Development',
'update_item' => 'Update New Development',
'add_new_item' => 'Add New Development',
'new_item_name' => 'New Developments',
),
'hierarchical' => true,
'show_ui' => true,
'show_tagcloud' => true,
'rewrite' => array( 'slug' => 'new-developments'),
'query_var' => 'new-developments',
'public'=>true)
);
}
我的自定义分类模板(taxonomy-new-developments.php)
<?php
/*
Template Name: Taxonomy New Developments
*/
?>
<?php get_header() ?>
<div id="columnswrapper" class="columns-1">
<?php get_sidebar(); ?>
<div id="content" class="norightsidebar">
<div class="inner">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?php $term = $wp_query->queried_object; echo '<h2>'.$term->name.'</h2>'; ?>
<?php $term = new WP_Query('post_type=listing', 'taxonomy=new-developments', 'field=slug', 'terms=doral'); ?>
<?php if ($term->have_posts()) : while ($term->have_posts()) : $term->the_post(); ?>
<?php include 'includes/variables.php' ?>
<div class="searchresult">
<?php
$arr_sliderimages = get_gallery_images();
//$firstimage = $arr_sliderimages[0];
//$arr_sliderimages = parse_url($firstimage);
$resized = aq_resize($arr_sliderimages[0], 250, 185, true);
?>
<div class="resultimage">
<?php include 'includes/bannerssmall.php'; ?>
<?php if ($mlslisting == "Yes" && $mlsnumber) { ?>
<a href="<?php bloginfo('url') ?>/idx/mls-<?php echo $mlsnumber ?>-"><img width="250" height="185" alt="Image for <?php the_title(); ?>" src="<?php echo $resized ?>" /></a>
<?php } else { ?>
<a href="<?php the_permalink(); ?>"><img width="250" height="185" alt="Image for <?php the_title(); ?>" src="<?php echo $resized ?>" /></a>
<?php } ?>
</div>
<div class="resultdetails">
<div class="primary-data">
<div class="address">
<?php if ($mlslisting == "Yes" && $mlsnumber) { ?>
<a href="<?php bloginfo('url') ?>/idx/mls-<?php echo $mlsnumber ?>-"><?php the_title() ?>, <?php echo $citystatezip ?></a>
<?php } else { ?>
<a href="<?php the_permalink() ?>"><?php the_title() ?>, <?php echo $citystatezip ?></a>
<?php } ?>
</div>
<div class="price">
<?php include 'includes/price.php'; ?>
</div>
</div>
<div class="secondary-data">
<?php if ($beds) { ?>
<div><?php echo $beds ?> <?php echo get_option('wp_bedrooms_text'); ?>, <?php echo $baths; ?> <?php echo get_option('wp_bathrooms_text'); ?></div>
<?php } ?>
<?php if ($homesize) { ?>
<div><?php echo get_option('wp_homesize_text') ?>: <?php echo $homesize ?></div>
<?php } ?>
<?php if ($lotsize) { ?>
<div><?php echo get_option('wp_lotsize_text') ?>: <?php echo $lotsize ?></div>
<?php } ?>
<?php if ($year) { ?>
<div><?php echo get_option('wp_yearbuilt_text') ?>: <?php echo $year ?></div>
<?php } ?>
</div>
<a class="button" href="<?php the_permalink(); ?>"><?php echo get_option('wp_read_more_text') ?></a>
</div><!-- end resultdetails -->
</div><!-- end searchresult -->
<?php endwhile; else: ?>
<p><strong>There are no items to display. Make sure you add 1 or more posts using the "Listings" category. Also, in Theme Options, make sure the slideshow is using the "Listings" category.</strong></p>
<?php endif;
wp_reset_query(); ?>
</div><!-- end inner -->
</div><!-- end content -->
</div><!-- end columnswrapper -->
<?php get_footer(); ?>
我一直试图让自己长时间处理,并迫切需要一些帮助来使这个工作。
提前感谢您的帮助。
========================================= 编辑:根据评论尝试了这一点,但它仍然无效 -
<?php
/*
Template Name: Taxonomy New Developments
*/
?>
<?php get_header() ?>
<div id="columnswrapper" class="columns-1">
<?php get_sidebar(); ?>
<div id="content" class="norightsidebar">
<div class="inner">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
<?php $term = $wp_query->queried_object; echo '<h2>'.$term->name.'</h2>'; ?>
<?php $term = new WP_Query('post_type=listing', 'taxonomy=new-developments', 'field=slug', 'terms=doral'); ?>
<?php if ($term->have_posts()) :
$args = array(
'post_type' => 'Listing',
'new-developments' => $term->slug
);
query_posts($args);
while ($term->have_posts()) : $term->the_post(); ?>
<?php include 'includes/variables.php' ?>
<div class="searchresult">
<?php
$arr_sliderimages = get_gallery_images();
//$firstimage = $arr_sliderimages[0];
//$arr_sliderimages = parse_url($firstimage);
$resized = aq_resize($arr_sliderimages[0], 250, 185, true);
?>
<div class="resultimage">
<?php include 'includes/bannerssmall.php'; ?>
<?php if ($mlslisting == "Yes" && $mlsnumber) { ?>
<a href="<?php bloginfo('url') ?>/idx/mls-<?php echo $mlsnumber ?>-"><img width="250" height="185" alt="Image for <?php the_title(); ?>" src="<?php echo $resized ?>" /></a>
<?php } else { ?>
<a href="<?php the_permalink(); ?>"><img width="250" height="185" alt="Image for <?php the_title(); ?>" src="<?php echo $resized ?>" /></a>
<?php } ?>
</div>
<div class="resultdetails">
<div class="primary-data">
<div class="address">
<?php if ($mlslisting == "Yes" && $mlsnumber) { ?>
<a href="<?php bloginfo('url') ?>/idx/mls-<?php echo $mlsnumber ?>-"><?php the_title() ?>, <?php echo $citystatezip ?></a>
<?php } else { ?>
<a href="<?php the_permalink() ?>"><?php the_title() ?>, <?php echo $citystatezip ?></a>
<?php } ?>
</div>
<div class="price">
<?php include 'includes/price.php'; ?>
</div>
</div>
<div class="secondary-data">
<?php if ($beds) { ?>
<div><?php echo $beds ?> <?php echo get_option('wp_bedrooms_text'); ?>, <?php echo $baths; ?> <?php echo get_option('wp_bathrooms_text'); ?></div>
<?php } ?>
<?php if ($homesize) { ?>
<div><?php echo get_option('wp_homesize_text') ?>: <?php echo $homesize ?></div>
<?php } ?>
<?php if ($lotsize) { ?>
<div><?php echo get_option('wp_lotsize_text') ?>: <?php echo $lotsize ?></div>
<?php } ?>
<?php if ($year) { ?>
<div><?php echo get_option('wp_yearbuilt_text') ?>: <?php echo $year ?></div>
<?php } ?>
</div>
<a class="button" href="<?php the_permalink(); ?>"><?php echo get_option('wp_read_more_text') ?></a>
</div><!-- end resultdetails -->
</div><!-- end searchresult -->
<?php endwhile; else: ?>
<p><strong>There are no items to display. Make sure you add 1 or more posts using the "Listings" category. Also, in Theme Options, make sure the slideshow is using the "Listings" category.</strong></p>
<?php endif;
wp_reset_query(); ?>
</div><!-- end inner -->
</div><!-- end content -->
</div><!-- end columnswrapper -->
<?php get_footer(); ?>
答案 0 :(得分:0)
你需要在while_posts循环之前传递下面的代码
$args = array(
'post_type' => 'Listing',
'new-developments' => $term->slug
);
query_posts($args);
if (have_posts()) :
while (have_posts()) :
the_post();
endwhile;
endif;
答案 1 :(得分:0)
你必须使用get_query_var http://codex.wordpress.org/Function_Reference/get_query_var来获取new_development下的当前类别,然后你可以查询该类别的帖子。
$current_cat = get_query_var('new-developments');
$args = array(
'post_type' => 'Listing',
'new-developments' => $current_cat
);
query_posts($args);
if (have_posts()) :
while (have_posts()) :
the_post();
endwhile;
endif;