Shortcode and Sliders
-
I am trying to get one of the sliders to show random posts. I thought I could make a page/post that queried 4 random posts in it and use that as the slider but it wouldn’t show the posts at all.
So I saw I could overlay a shortcode on the page instead. So I made a function of the exact same query and gave it a shortcode. I used that shortcode on an empty page and put that page into my slider. It showed the 4 random posts but it broke the slider because the content was not actually in the slide.
I was wondering how to fix this?
The function I am using is this:
function randompost_sc(){ $random = new WP_Query (array( 'orderby' => 'rand', 'post_type' => array('animereviews', 'animerants', 'gamereviews', 'gamerants'), 'posts_per_page' => 4) ); if ($random->have_posts()) : while ($random->have_posts()) : $random->the_post(); ?> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(64,36)); ?></a> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php wp_reset_postdata(); ?> <?php endwhile ?> <?php endif; } add_shortcode( 'randomshort', 'randompost_sc');
The result looks like this now:
https://45.55.62.181/wordpress/
Is this even doable? Thanks
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Shortcode and Sliders’ is closed to new replies.