【问题标题】:need help on php code creating error wordpress custom fields需要有关 php 代码创建错误 wordpress 自定义字段的帮助
【发布时间】:2016-08-04 19:55:19
【问题描述】:

我已将此代码用于滑块以显示选择用户选择类别的帖子,但在添加此代码后,即使我尝试过,它也不会在自定义字段或任何其他 php 代码之后选择..

这是我应用的代码

<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 或该行下方是错误的.. 我错过了一些东西.. 提前致谢。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您必须错误地使用 get_post_custom。从法典中, get_post_custom

    返回一个包含所有自定义字段的多维数组 特定的帖子或页面。

    get_post_custom($post_id);
    

    【讨论】:

    • 对不起,我没听懂你..我必须使用不正确的东西?我用 get_field('business_solutions_category_name');要获取自定义字段插件(FIELD)的值,我正在使用该插件。我结束循环正确吗?
    • 警告:urlencode() 期望 parameter1 是字符串。这是我现在得到的一个错误,在那段代码之后。
    • 我已经给出了另一个答案来向您展示代码,它很长。
    【解决方案2】:
    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-02
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多