Advertisement
salmancreation

A Simple Slider Setup Wordpress Development

Oct 30th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. Example #4: A Simple Slider Setup
  2.  
  3. When using WordPress to build corporate websites, portfolios or web magazines, sliders have become a "must-have" industrial standard. I'm not really a fan of sliders (I think it's bad UX) but the web seems to like it, so I can't just say no to my clients while making websites for them. If they want sliders, I use a simple query using the WP_Query class:
  4.  
  5. <?php
  6.  
  7. // Setup arguments.
  8. $args = array(
  9.     // Get the "slider" post type.
  10.     'post_type' => 'slider',
  11.     // Get a specific slider category.
  12.     'category_name' => 'home-slides',
  13.     // Get all slides and don't paginate.
  14.     'nopaging' => true
  15. );
  16.  
  17. // Instantiate new query instance.
  18. $my_query = new WP_Query( $args );
  19.  
  20. ?>
  21.  
  22. The 'cat' argument can be used to retrieve slides from different categories so you can separate slide groups and use multiple sliders on multiple pages. If you're going to use just one slider in your website, you can delete that line and you're good to go.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement