WordPress.org

Support

Support » How-To and Troubleshooting » Hooking your slider up to the backend of wordpress

Hooking your slider up to the backend of wordpress

  • If you have used a slider or similar API then you know that having to rewrite html is a pain in the butt to add or remove slider images.

    Most slider APIs have you call an unordered list as your slider…and a list item is the actual image in the slider.

    Example

    <ul class="slider">
    	<li><img src=""/></li>
    	<li><img src=""/></li>
    	<li><img src=""/></li>
    </ul>

    If you wanted to hook this up very easily to the wordpress backend you could using

    <div class="slider">
    <ul>
    <?php
    
    // The Query
    $the_query = new WP_Query( $args );
    
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    	echo '<li>' . if ( has_post_thumbnail() ) {
    	the_post_thumbnail();
    }  . '</li>';
    endwhile;
    
    // Reset Post Data
    wp_reset_postdata();
    ?>
    </ul>
       </div>

    If you pass $args an argument for say…a category slider posts See WP_Query and you make sure each post that was in that category had a featured image. Then you effectively have an easy way to add & upload slider images.

    Dont forget to add add_theme_support( 'post-thumbnails' ); to your functions.php file.

    Thank you, wordpress users.

  • The topic ‘Hooking your slider up to the backend of wordpress’ is closed to new replies.