2016-08-04 83 views
0

我已經把這個代碼滑塊來顯示帖子拿起用戶選擇類別的類別,但添加此代碼後,它不會選擇後自定義字段例如或任何其他的PHP代碼甚至我試過..需要幫助的PHP代碼創建錯誤wordpress自定義字段

這裏是我申請

<div class="blog-posts-slider"> 
<?php $temp_query = $wp_query; 
       $category_name = get_field('business_solutions_category_name');  
        query_posts(array(
          'category_name' => $category_name, 
          'posts_per_page' => 5 
        ) 
       ); 
       while (have_posts()) : the_post(); 
       $thumb_id = get_post_thumbnail_id(); 
       $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true); 
       $thumb_url = $thumb_url_array[0]; 
       ?> 

       <div class="slider-single-post"> 
        <div class="blog-image" style="background-image : url('<?php the_post_thumbnail_url(); ?>');"></div> 
        <div class="slider-post-text"> 
         <h3><?php the_title(); ?></h3> 
         <p><?php the_excerpt(); ?></p> 
         <a href="<?php the_permalink(); ?>">Read More</a> 
        </div> 
       </div> 

       <?php endwhile; 
       $wp_query = $temp_query; ?> 
</div> 

的代碼我不熟悉,許多用PHP ..但我認爲這是對ENDWHILE或線下的錯誤...我缺少的東西.. 在此先感謝。

回答

0

您必須錯誤地使用get_post_custom。從代碼中, get_post_custom

返回一個多維數組,其中包含特定帖子或頁面的所有自定義字段。

get_post_custom($post_id); 
+0

對不起,我沒有得到你.. 我有錯誤使用的東西嗎? 和我用get_field('business_solutions_category_name'); 以獲取我使用該插件的自定義字段插件(FIELD)的值。 我結束循環是否正確? – emppeak

+0

你有沒有試過get_post_custom($ post_id)? –

+0

警告:urlencode()期望parameter1是字符串。 這是我現在得到的錯誤,之後的代碼。 – emppeak

0
Problem is, custom fields aren't working for the div class-above-footer. 
<div class="blog-posts-bottom"> 
      <div class="container"> 
       <h2>Connect with C-Level Executives</h2> 
       <div class="blog-posts-slider"> 

        <?php $temp_query = $wp_query; 
        $category_name = get_field('business_solutions_category_name');  
         query_posts(array(
           'category_name' => $category_name, 
           'posts_per_page' => 5 
         ) 
        ); 
        while (have_posts()) : the_post(); 
        $thumb_id = get_post_thumbnail_id(); 
        $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true); 
        $thumb_url = $thumb_url_array[0]; 
        ?> 

        <div class="slider-single-post"> 
         <div class="blog-image" style="background-image : url('<?php the_post_thumbnail_url(); ?>');"></div> 
         <div class="slider-post-text"> 
          <h3><?php the_title(); ?></h3> 
          <p><?php the_excerpt(); ?></p> 
          <a href="<?php the_permalink(); ?>">Read More</a> 
         </div> 
        </div> 

        <?php endwhile; 
        $wp_query = $temp_query; ?> 

       </div> 
      </div> 
     </div> 

     <div class="above-footer-link"> 
      <div class="container"> 
       <h2><?php the_field('business_solutions_abovefooter_heading');?></h2> 
       <a href="<?php the_field('business_solutions_abovefooter_button_link');?>"><?php the_field('business_solutions_abovefooter_button_text');?></a> 
      </div> 
     </div>