Wordpress类别页面未正确返回数组

时间:2013-08-17 07:33:15

标签: php arrays wordpress wordpress-theming

我正在编辑我的类别页面。使用一些自定义字段我定义了一个图像。对于某个类别中的每个帖子,我想将此自定义图像添加到我将变成图像库的数组中。我正在使用下面的代码,但出于某种原因,当涉及到爆炸数组时,我得到的是一个图像(对应于加载的最后一个帖子)。我敢肯定,我可能只是放错了地方,但我无法理解。任何帮助将不胜感激。

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 

                        $gallery_images = get_custom_field('catImage:to_array');


                            $thumbs_html = array();
                            foreach ($gallery_images as $galleryID) {
                                $attachment = get_post( $galleryID );

                                $description = get_custom_field('catIntro:do_shortcode'); //get pages introductory text
                                $caption = get_the_title(); //get page title

                                $button_html .= '<div id="description-button-' . $gallery_images_count . '" class="show-description-button">Show Caption</div>';
                                $description_html .= '<div id="description-' . $gallery_images_count . '" class="photoDescription" style="display:none;">' . $description . '</div>';
                                $caption_html .= '<div id="caption-' . $gallery_images_count . '" class="photoCaption" style="display:none;">' . $caption . '</div>';

                                $thumb_img = wp_get_attachment_image_src( $galleryID, 'thumbnail' );    //thumbnail src
                                $full_img = wp_get_attachment_image_src( $galleryID, 'full' );          //full img src

                                $thumbs_html[] = '<div class="indvlThumbCont"><a href="' . $full_img[0] . '" id="description-button-' . $gallery_images_count . '" class="thumbLink" target="_blank"><img  class="thumbImg" src="' . $thumb_img[0] .'"></a></div>';

                                $gallery_images_count++;



                            }//end forEach


                    //calculate the width of the thumbar
                    $widthPerImg = 157;
                    $thumbBarWidth = $gallery_images_count * $widthPerImg;
                    print $gallery_images_count;

            ?>


            <?php endwhile; else: ?>
            <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
            <?php endif; ?> 


            <div id="thumbsBar">
                <div id="left" class="scrollCtrl left desktopOnly"><span></span></div>

                    <div class="toHideScrollBar" id="toHideScrollBar">
                    <div class="moveCanvas" style="width:<?php echo $thumbBarWidth; ?>px;">
                        <?php echo implode("\n", $thumbs_html); ?>
                    </div>
                    </div>

                <div id="right" class="scrollCtrl right desktopOnly"><span></span></div>
                <span id="total_number_in_gallery " class="<?php echo $gallery_images_count; ?>"></span>
            </div>

1 个答案:

答案 0 :(得分:0)

如果你使用像TwentyTwelve这样的主题(默认情况下只在类别页面上显示一个帖子)那么问题出在那里。你可以解决这个问题(如果修改主循环没问题),在代码之前添加它:

query_posts('showposts=y&cat=x');
相关问题