1

这是我的代码(那么我将如何从帖子中获得最低价格)

  <div>

它正在从父类别中获取子类别

    <?php 
    $subcategories = get_categories('&child_of='.$cat.'&hide_empty');
    foreach ($subcategories as $subcategory) {
    ?>

 <div class="cat-con">
          <?php
          $subCatId=sprintf('%s',$subcategory->term_id); //the_content(); 
          query_posts('cat='.$subCatId.'&order=ASC&meta_key=price&orderby=meta_value_number');

这部分代码让我了解自定义字段的价格

while ( have_posts() ) : the_post();

      /************************************************************************/

      $price=$post->ID; 
      $price = get_post_meta($price, 'price', true);
      if ($price <= 3500) {
      $minPrice=$price;
      /************************************************************************/
          ?>

     <div class="cat-img">
     <?php $postID=$post->ID; $image = wp_get_attachment_image_src (get_post_thumbnail_id( $pageID ),'medium', true) ; ?>
     <img width="445" height="209" src="<?php echo $image[0]; ?>" alt="" />
     </div>
                  <div class="clear"></div>
                  <div class="cat-heading">
                      <?php echo sprintf('<a href="%s">%s</a>',get_category_link($subcategory->term_id), apply_filters('get_term', $subcategory->name));?></a>
                  </div>
                  <div class="clear"></div>
                  <div class="cat-con-text">
                      <p><?php the_content(); ?><p>
                  </div>
                  <div class="clear"></div>

                  <div>
                      <div class="floatright">
                          <a href="<?php echo sprintf('%s',get_category_link($subcategory->term_id)); ?>"><img src="<?php bloginfo( 'template_directory' );?>/images/btn-view.png" alt="" /></a>
                      </div>
                      <div class="cat-price">Price Start From &pound;<?php echo $minPrice?></div>
                      <div class="clear"></div>
                  </div>
                      <?php    
              } // end if $price
              endwhile; ?>
        </div>
        <?php } //end foreach; ?>
        <div class="clear"></div>
    </div>
    <!--End Category-->
4

2 回答 2

1

假设您将$minPrice在底部(循环外)回显:

while ( have_posts() ) : the_post();

/************************************************************************/

$price=$post->ID; 
$price = get_post_meta($price, 'price', true);

if ( !isset( $minPrice ) || $price < $minPrice )
    $minPrice = $price;

/************************************************************************/
于 2013-01-30T07:03:30.883 回答
0
`while ( have_posts() ) : the_post();
$price1 = get_post_meta($post->ID, "price", false);
echo $minPrice = min($price1);
endwhile;
`

/ * ** * ** * ** * ** * ** * ** * ** * ** /

It is getting me value array
Array ( [0] => 2500 )
Array ( [0] => 3500 )
于 2013-01-30T07:20:41.060 回答