0

我在使用 wordpress 的调试模式下遇到问题。在我的特色滑块中出现错误 Notice: Object of class WP_Query could not be converted to int in on line

我正在为我的滑块使用下面的代码

<div id="<?php slider_class() //Theme function ?>" class="clearfix">

    <!--[BEGIN: Slider wrapper]-->
    <div id="slides-wrapper" <?php slider_wrapper_class() //Theme function ?>>
        <!--[BEGIN: #Slides]-->
        <div id="slides" class="<?php slides_class() //Theme function ?> clearfix">
            <!--[BEGIN: Slides_container]-->
            <div class="slides_container <?php slides_class() //Theme function ?>">

                <?php
                $featuredPosts = new WP_Query();
                $featuredPosts->query('showposts='.get_option('mp_slides_no').'&category_name='.get_option('mp_featured_cat').'');

                for($i=1; $i<=$featuredPosts; $i++) { // second for() loop for post slides
                while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); // loop for posts
                ?>

                <?php if (get_option('mp_slides_content') === "content_s") { ?>
                <!--[BEGIN: ALL SLIDES ++]-->
                <div class="slide clearfix">
                    <!-- thumbnail start -->
                    <?php mp_thumb('featured-thumbnail','featured-slider-thumbnail','480'); //Theme function  ?>
                    <!-- end of thumbnail -->

                    <div class="featured-excerpt">
                        <h2 class="title"><a href="<?php the_permalink(); ?>"><?php echo substr($post->post_title,0,50); // short title ?>...</a></h2>

                        <?php the_excerpt(); ?>
                        <br />
                        <a href="<?php the_permalink(); ?>" class="featured-readmore clearfix"><span>Read more</span><img src="<?php bloginfo('template_directory'); ?>/images/button-arrow.png" alt="readmore" width="24" height="24" /></a>
                    </div>

                </div>
                <!--[END: ALL SLIDES ++]-->

                <?php } elseif (get_option('mp_slides_content') === "image_s") { ?>

                <!--[image slider start]-->

                <!--[BEGIN: ALL SLIDES ++]-->
                <div class="slide clearfix">
                    <!-- thumbnail start -->
                    <?php if (get_option('mp_slides_style') === "fixed") { ?>

                        <?php mp_thumb('featured-thumbnail','featured-slider-image920','920'); //Theme function  ?>

                    <?php } else { ?>

                        <?php mp_thumb('featured-thumbnail','featured-slider-image960','960'); //Theme function  ?>

                    <?php } ?>
                    <!-- end of thumbnail -->

                </div>
                <!--[END: ALL SLIDES ++]-->             

                <!--[end of image slider]-->

                <?php } ?>

                <?php endwhile;
                } // end for() loop number 2
                ?>

            </div>
            <!--[END: Slides_container]-->

            <a href="#" class="prev"></a>
            <a href="#" class="next"></a>

        </div>
        <!--[END: #Slides]-->

    </div>
    <!--[END: Slider wrapper]-->

</div>

//theme function只不过是为了风格而改变班级

4

1 回答 1

1

您应该删除 for 循环,不要认为 $featuredPosts 是一个有效的 int 字段,这可能是它所抱怨的......这也会循环多次您已经在使用 while have_posts() 的帖子

 <?php
                $featuredPosts = new WP_Query();
                $featuredPosts->query('showposts='.get_option('mp_slides_no').'&category_name='.get_option('mp_featured_cat').'');

                //for($i=1; $i<=$featuredPosts; $i++) { // second for() loop for post slides
                while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); // loop for posts
                ?>
于 2012-03-05T20:24:44.357 回答