Slider Revolution WP
09.27.2016
Post ID’s for a Specific Posts slider can be changed inside a shortcode like the following code example.
[rev_slider alias="my-post-based-slider"][gallery ids="0, 255, 256"][/rev_slider]
And since post ID’s can be defined inside the shortcode, this can be expanded with a more complex WP Query. In the following example, the PHP code can be added to a theme page template such as “header.php”, etc, and setup to only be displayed for specific pages, with different content based on any given page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
// array of pages to add the slider to $pages_to_add_slider_to = array( 223, 224 ); // ID of current page $current_page = get_the_ID(); // if current page ID is included in the "pages_to_add_slider" list if(in_array( $current_page, $pages_to_add_slider_to )) { // https://codex.wordpress.org/Class_Reference/WP_Query $query_args = array(); // apply different queries based on the current page ID switch($current_page) { // if page ID = 223 case 223: $query_args['author'] = '1'; break; // if page ID 224 case 224: $query_args['author'] = '2'; break; } $post_loop = new WP_Query( $query_args ); $post_list = array(); while ( $post_loop->have_posts() ) : $post_loop->the_post(); $post_list[] = get_the_id(); endwhile; // only add slider if query returned a result if(!empty( $post_list )) { echo do_shortcode( '[rev_slider alias="tester"]' . '[gallery ids="0,' . implode( ",", $post_list ).'"]' . '[/rev_slider]' ); } } |