我需要分类类别中标记为“特色”的帖子首先显示
https://yoga.gcclients.com/listing-category/bucks-county/
目前,它正在从标记为“特色”的业务列表分类中的所有帖子中提取帖子,而不是从用户正在查看的页面类别中提取帖子
因此,如果在雄鹿县网页上,它应该拉标签为“特色”的帖子,并且只在雄鹿县类别中
或者如果他们查看其他类别,例如新泽西州https://yoga.gcclients.com/listing-category/new-jersey/ 它应该拉标签为“特色”的帖子,这些帖子只属于新泽西类别
以下是我们当前使用的代码:
<!-- /* START FEATURED BUSINESSES */ -->
<ul class="archive-businesses">
<?php
$args = array( \'post_type\' => \'businesslistings\', \'posts_per_page\' => 6, \'orderby\' => rand, \'tag\' => \'featured\' );
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li class="archive-bizlist">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(300,300) ); ?></a>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<div id="archive-bizlisting-address">
<?php if(get_post_meta($post->ID, \'biz_street_address\', true)): ?>
<i><?php echo get_post_meta($post->ID, \'biz_street_address\', true); ?></i><br />
<?php endif; ?>
<?php if(get_post_meta($post->ID, \'biz_city\', true)): ?>
<i><?php echo get_post_meta($post->ID, \'biz_city\', true); ?>,</i>
<?php endif; ?>
<?php if(get_post_meta($post->ID, \'biz_state\', true)): ?>
<i><?php echo get_post_meta($post->ID, \'biz_state\', true); ?></i>
<?php endif; ?>
<?php if(get_post_meta($post->ID, \'biz_zip_code\', true)): ?>
<i><?php echo get_post_meta($post->ID, \'biz_zip_code\', true); ?></i>
<?php endif; ?>
</div>
<?php the_excerpt(); ?>
</li>
<?php endwhile;?>
</ul>
<?php endif; ?>
<!-- /* END FEATURED BUSINESSES */ -->
SO网友:ThatDudeLarry
我真的希望有人能给你一个更简单的答案,但这几乎是我目前能想到的全部。
如果您同意将所有列表放在一个页面上,您可以这样做:
<?php
// Get the slug of the page to use in our category argument
global $post;
$post_slug = $post->post_name;
?>
<?php
$args = array(
\'category_name\' => $post_slug,
\'post_type\' => \'businesslistings\',
\'posts_per_page\' => -1,
\'orderby\' => rand,
\'tag\' => \'featured\'
);
$featured_query = new WP_Query( $args );
?>
<?php if ( $featured_query->have_posts() ) : ?>
<?php while ( $featured_query->have_posts() ) : $featured_query->the_post(); ?>
// Display featured stuff
<?php endwhile;?>
<?php endif; ?>
<?php
$args = array(
\'category_name\' => $post_slug,
\'post_type\' => \'businesslistings\',
\'posts_per_page\' => -1,
\'orderby\' => rand,
// x below should be replaced with the featured tag\'s ID (link for instructions will be below)
\'tag__not_in\' => \'x\'
);
$standard_query = new WP_Query( $args );
?>
<?php if ( $standard_query->have_posts() ) : ?>
<?php while ( $standard_query->have_posts() ) : $standard_query->the_post(); ?>
// Display standard stuff stuff
<?php endwhile;?>
<?php endif; ?>
参考文献:
在中使用WordPress标记WP_Query
: WordPress Codex
获取页面段塞:Stack Exchange
获取标签ID:Stack Exchange