2016-08-04 86 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>