【问题标题】:Wordpress, Recent Posts in SliderWordpress,滑块中的最新帖子
【发布时间】:2013-01-31 21:52:47
【问题描述】:

我为 Wordpress 编写了一小段代码,它将在滑块中显示最新的前 4 个帖子(Filament Group Responsive Carousel)。它可以工作,显示帖子并滑动它们等,但有 4 个滑块,每个滑块中有 4 个帖子。我一定是用WP_Query() 错误地定位了一些代码。这是我的代码:

<div class="carousel slider carousel-slide" data-transition="slide" data-autoplay="" data-interval="5000" data-paginate="true">
    <?php
        $topNews = new WP_Query();
        $topNews->query('showposts=4'); 
        while ($topNews->have_posts()) : $topNews->the_post(); ?>
            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <header class="entry-header">
                    <?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                        the_post_thumbnail('full');
                } ?>
                    <h1 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'android_and_tea' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
                </header>
            </div>
        <?php endwhile; ?>
</div>

所以我的问题是,我需要重新定位/更改/添加/删除什么代码才能让它显示一个带有 4 个最新帖子的滑块,而不是 4 个带有 4 个最新帖子的滑块?

【问题讨论】:

  • 你的整个轮播幻灯片 div 是否在页面中重复了 4 次?
  • @PhilippeBoissonneault 是的。但是我想要的 4 个帖子都在那里并且工作正常(滑动和一切)。
  • 如果你有while(have_posts): the_post();,请看上面这组代码...
  • 只是一个想法尝试将&lt;?php wp_reset_query(); ?&gt;放在endwhile之后

标签: php javascript html css wordpress


【解决方案1】:

我的猜测是您将代码调用到循环中。:

if(have_posts()) while(have_posts()): the_post();

//HERE IS YOUR CODE

endwhile;

你必须在这个循环之前或之后移动你的代码,或者删除循环前:

//if(have_posts()) while(have_posts()): the_post();

//HERE IS YOUR CODE

//endwhile;

//HERE IS YOUR CODE
if(have_posts()) while(have_posts()): the_post();

endwhile;

【讨论】:

  • 嗨,抱歉,这些都不起作用。滑块应该在的地方有空白,并且没有在 div 中加载任何内容。感谢您的尝试:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多