0

我正在开发一个 wordpress 3.3.1 主题,但我在使用 single.php 文件时遇到了问题。它显示 - 无论您选择什么帖子(&p=111 例如) - 只显示最新帖子的内容。

这是我的循环:

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


            <h1 class="page-title"><?php the_title() ?></h1>

            <?php if (has_post_thumbnail( $post->ID ) ): ?>
            <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
            <img src="<?php echo $image[0]; ?>" class="cover" />
            <?php endif; ?>

            <p class="page-text">
                <?php the_content(); ?>     
            </p>

            <?php endwhile; ?>
            <?php endif; ?>

有什么问题?我希望你明白我的问题。谢谢!

编辑:

我最近更新了头文件。当我删除这个循环时,它工作正常:

                        <ul class="nav-dropdown">
                        <?php
                            $cat_args = array(
                              'orderby' => 'name',
                              'order' => 'ASC',
                              'child_of' => 5,
                              'exclude' => '1,2,3,4,5,6,8,9,10,11,12,13,14'
                            );
                            $categories = get_categories($cat_args); 
                            foreach($categories as $category) {

                                 $post_args = array(
                                  'category' => $category->term_id
                                );
                                $posts = get_posts($post_args);

                                foreach($posts as $post) {
                        ?>
                            <li class="nav-dropdown"><a href="<?php the_permalink(); ?>" class="pagelink"><?php the_title(); ?></a></li>
                        <?php
                                }
                            }
                        ?>
                        </ul>
4

2 回答 2

2

我会将标题中的变量名称更改为$postWordpress 为处理单个帖子页面保留的变量名称。

于 2012-04-07T10:35:40.937 回答
1

我不确定,但请将$post变量更改为任何其他变量,然后尝试可能会解决您的问题。

因为$post是post的全局变量。

于 2012-04-07T12:14:18.957 回答