【问题标题】:Blog category specific slider for wordpress home page?wordpress主页的博客类别特定滑块?
【发布时间】:2012-11-13 06:49:17
【问题描述】:

我希望有人能指出我正确的方向或提供一些指导。我目前正在为我的主页滑块使用响应式幻灯片插件。它工作得很好,但它创建了一个自定义的帖子类型。这很好,但我想通过它运行我的博客文章。本质上,我想创建一个类别并将其命名为“滑块”,并让该类别中的博客文章使用滑块。我使用这个特定滑块的原因是因为它适合响应式主题。使用我当前的设置(下面的代码)有什么简单的方法可以做到这一点,或者有人可以指出我如何实现这一点的正确方向吗?提前致谢! (网站不在现场,它在我电脑的本地主机上)

在主题首页使用简码

           {<div id="flexfix" class="span11"> 
           <?php do_shortcode( '[responsive_slider]' ); ?>
           </div><!-- End Flexslider -->}

响应式滑块查询

{function responsive_slider() {

$slides = new WP_Query( array( 'post_type' => 'slides', 'order' => 'ASC', 'orderby' => 'menu_order' ) );

if ( $slides->have_posts() ) : ?>

    <div class="responsive-slider flexslider">

        <ul class="slides">

        <?php while ( $slides->have_posts() ) : $slides->the_post(); ?>

            <li>

                <div id="slide-<?php the_ID(); ?>" class="slide">

                    <?php global $post; ?>

                        <?php if ( has_post_thumbnail() ) : ?>

                        <!--edited by david crothers 11/8/12-->
                            <!--<?php echo get_post_meta( $post->ID, "_slide_link_url", true ); ?><?php the_title_attribute(); ?>-->
                            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
                                <?php the_post_thumbnail( 'slide-thumbnail', array( 'class' => 'slide-thumbnail' ) ); ?>
                            </a>

                                <h2 class="slide-title"><?php the_title()?></h2>

                        <?php endif; ?>


                </div><!-- #slide-x -->

            </li>

        <?php endwhile; ?>

        </ul>

    </div><!-- #featured-content -->}

【问题讨论】:

    标签: wordpress slider responsive-design


    【解决方案1】:

    只需更改 WP_Query 中的参数即可。将 post_type 更改为标准“post”,然后将其设置为您的新类别;

     $slides = new WP_Query( array( 'post_type' => 'post', 'category_name' => 'slider', 'order' => 'ASC', 'orderby' => 'menu_order' ) );
    

    http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

    【讨论】:

    • 感谢您的帮助!我以为这很容易。感谢您也将我指向 Codex!
    猜你喜欢
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    相关资源
    最近更新 更多