Custom Post type slider

15,481

There is a great slider by woothemes called flexslider personally I use it on all my sites and you can use it without a plugin. Download the slider from that link i provided.

copy the flexslider.css file and jquery.flexslider-min.js file into your theme folder.

in your header.php

    <link rel="stylesheet" href="<YOUR_THEME_LINK>/flexslider.css" type="text/css">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="<YOUR_THEME_LINK>/jquery.flexslider-min.js"></script>
<script type="text/javascript">(function($) {
    $(window).load(function() {
        $('#slider .flexslider').flexslider({
               animation: 'slide',
                slideshowSpeed: 9000,
                animationSpeed: 900,
                pauseOnAction: true,
                pauseOnHover: true,
                controlNav: false,
                directionNav: true, 
                controlsContainer: ".flexslider",
        });
    });
})(jQuery)</script>

in your homepage file (or anywhere you want the slider to show)

<section id="slider">
      <div class="flexslider">
        <ul class="slides">
        <?php query_posts(array('post_type' => '<YOUR_CUSTOM_POST_TYPE>','orderby' => 'rand')); if(have_posts()) : while(have_posts()) : the_post();?>
            <li class="slide">
            <?php the_title(); ?>
            <?php the_excerpt(); ?>
            <?php the_post_thumbnail(); ?>
          </li>
        <?php endwhile; endif; wp_reset_query(); ?>
        </ul>
    </div>
</section>
Share:
15,481
BrianM
Author by

BrianM

Updated on June 04, 2022

Comments

  • BrianM
    BrianM almost 2 years

    I've looked and looked, but I can't find a Wordpress plugin that gives me ALL the following functionality available in a Slider:

    • Display custom posts from a custom post type I have developed myself - - displays Featured image, title and excerpt (not full post)
    • Display in random order – from a list of 100’s of custom posts of that type
    • Responsive so adapts to screen/container size

    Images and excerpts are of varying sizes.

    As a bonus I’d like to display some custom taxonomy names associated with the posts as well, though that’s not as important.

    I've found ones that do everything except display in random order as an option, or they are not responsive, or they don's support custom post types, or they expect you to create a new custom post type of a particular type specified by the plugin.

    I don't mind paying for the right one if it's out there.