WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Category specific slider? (4 posts)

  1. cruthas
    Member
    Posted 1 year ago #

    I was hoping someone might be able to point me in the right direction or provide some guidance. I am currently using a responsive slide plugin for my home page slider. It works great but it creates a custom post type. That is fine, but I would like, instead, to run my blog posts through it. Essentially I would like to create a category and name it "slider" and have the blog posts from that category use the slider. Any easy way to do that using my current setup (below) or can someone point me in the right direction on how to accomplish this? Thanks in advance! (website isn't live, it's on my computer's localhost)

    Using shortcode on front page of theme

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

    Responsive slider query

    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 -->
  2. Tom Combs
    Member
    Posted 1 year ago #

    Try changing this:

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

    to this:

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

    I can't test that at the moment, but try it and let me know if it works.

    Also, if this code is in the plugin core files then make sure you make a backup of it. because your changes will be overwritten if you update that plugin.

  3. cruthas
    Member
    Posted 1 year ago #

    Yup, I ended up using

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

    works great. Codex is here:
    http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

    Thanks for the help!

  4. Tom Combs
    Member
    Posted 1 year ago #

    Glad you it worked out for you!

    If you could mark this thread as "Solved", that would be great.
    (it's in the sidebar on the right) :-)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.