来自loop-ad_listing.php
的此代码使所有帖子结果显示在列表中。但现在我想把特色帖子放在非特色上面(order = featured,然后是非特色)。我需要在此代码中添加哪些代码才能首先显示精选帖子?
任何帮助表示赞赏:)
<?php if ( have_posts() ) : ?>
<div id="page-<?php echo $paged ?>">
<?php while ( have_posts() ) : the_post(); ?>
<?php
if ( get_post_meta($post->ID, 'location', true) )
$make_address = get_post_meta($post->ID, 'location', true);
else
$make_address = get_post_meta($post->ID, 'cp_street', true) . ' ' . get_post_meta($post->ID, 'cp_city', true) . ' ' . get_post_meta($post->ID, 'cp_state', true) . ' ' . get_post_meta($post->ID, 'cp_zipcode', true);
?>
<div id="post-id-<?php the_ID(); ?>" class="post-wrapper">
<div class="post-block">
<?php if ( is_sticky() ) echo '<strong>FEATURED</strong>'; ?>
<div class="grid_100">
<?php if ( get_option('cp_ad_images') == 'yes' ) cp_ad_loop_thumbnail(); ?>
<h3 class="post-title"><a href="<?php the_permalink(); ?>"><?php if ( mb_strlen( get_the_title() ) >= 75 ) echo mb_substr( get_the_title(), 0, 75 ).'...'; else the_title(); ?></a></h3>
</div>
<div class="post-desc">
<?php echo $make_address; ?>
<div class="post-debug">
<!--<h4>Description:</h4>
<?php echo cp_get_content_preview( 160 ); ?>--!>
</div>
</div>
</div><!-- /post-block -->
</div><!-- /post-wrapper -->
<?php endwhile; ?>
</div><!-- /page -->
<?php else: ?>
<div class="block"><center>Sorry, no results found...</center></div>
<?php endif; ?>
答案 0 :(得分:0)
您可以使用orderby
在使用指定的meta_value
meta_key
cp_ad_featured_thumbnail
循环之前使用query_posts()
。这假定<?php
$args = array( "orderby"=>"meta_value", "meta_key"=>"cp_ad_featured_thumbnail" );
query_posts( $args );
?>
<?php if ( have_posts() ) : ?>
<div id="page-<?php echo $paged ?>">
<?php while ( have_posts() ) : the_post(); ?>
<!-- POST CONTENT -->
<?php endwhile; endif; ?>
未设置为非功能帖子。
{{1}}
答案 1 :(得分:0)
<?php
<!-- display all post (exclude non-sticky post) -->
query_posts(array("post__in"=>get_option("sticky_posts")));
if ( have_posts() ) : ?>
<div id="page-<?php echo $paged ?>">
<?php while ( have_posts() ) : the_post(); ?>
<?php
if ( get_post_meta($post->ID, 'location', true) )
$make_address = get_post_meta($post->ID, 'location', true);
else
$make_address = get_post_meta($post->ID, 'cp_street', true) . ' ' . get_post_meta($post->ID, 'cp_city', true) . ' ' . get_post_meta($post->ID, 'cp_state', true) . ' ' . get_post_meta($post->ID, 'cp_zipcode', true);
?>
<div id="post-id-<?php the_ID(); ?>" class="post-wrapper">
<div class="post-block">
<?php echo '<strong>FEATURED</strong>'; ?>
<div class="grid_100">
<?php if ( get_option('cp_ad_images') == 'yes' ) cp_ad_loop_thumbnail(); ?>
<h3 class="post-title"><a href="<?php the_permalink(); ?>"><?php if ( mb_strlen( get_the_title() ) >= 75 ) echo mb_substr( get_the_title(), 0, 75 ).'...'; else the_title(); ?></a></h3>
</div>
<div class="post-desc">
<?php echo $make_address; ?>
<div class="post-debug">
<!--<h4>Description:</h4>
<?php echo cp_get_content_preview( 160 ); ?>--!>
</div>
</div>
</div><!-- /post-block -->
</div><!-- /post-wrapper -->
<?php endwhile; ?>
</div><!-- /page -->
<?php endif; ?>
<?php
<!-- display all post (exclude non-sticky post) -->
query_posts(array("post__not_in"=>get_option("sticky_posts")));
if ( have_posts() ) : ?>
<div id="page-<?php echo $paged ?>">
<?php while ( have_posts() ) : the_post(); ?>
<?php
if ( get_post_meta($post->ID, 'location', true) )
$make_address = get_post_meta($post->ID, 'location', true);
else
$make_address = get_post_meta($post->ID, 'cp_street', true) . ' ' . get_post_meta($post->ID, 'cp_city', true) . ' ' . get_post_meta($post->ID, 'cp_state', true) . ' ' . get_post_meta($post->ID, 'cp_zipcode', true);
?>
<div id="post-id-<?php the_ID(); ?>" class="post-wrapper">
<div class="post-block">
<div class="grid_100">
<?php if ( get_option('cp_ad_images') == 'yes' ) cp_ad_loop_thumbnail(); ?>
<h3 class="post-title"><a href="<?php the_permalink(); ?>"><?php if ( mb_strlen( get_the_title() ) >= 75 ) echo mb_substr( get_the_title(), 0, 75 ).'...'; else the_title(); ?></a></h3>
</div>
<div class="post-desc">
<?php echo $make_address; ?>
<div class="post-debug">
<!--<h4>Description:</h4>
<?php echo cp_get_content_preview( 160 ); ?>--!>
</div>
</div>
</div><!-- /post-block -->
</div><!-- /post-wrapper -->
<?php endwhile; ?>
</div><!-- /page -->
<?php else: ?>
<div class="block"><center>Sorry, no results found...</center></div>
<?php endif; ?>