There are many plugins out there that an generate a random post to be inserted into your website. An example of such a random post is shown to the right of this entry in the box-set off. Some of the plugins come with their own shortcodes. But there’s no need to install another plugin if you have Shortcodes Ultimate installed.
Shortcodes Ultimate by Vladimir Anokhin is a popular plugin for WordPress supplying numerous helpful shortcodes to add various features to your posts.
This method permits you to customize the random listing so that it can include only the title, the title and the featured image, or even the entire content.
<div class="su-posts su-posts-teaser-loop"<?php
$current_post_id = get_the_ID();
$posts = new WP_Query( array ( 'orderby' => 'rand', 'posts_per_page' => '1', 'post__not_in'=>array($current_post_id)));
if ( $posts->have_posts() ) {
while ( $posts->have_posts() ) :
$posts->the_post();
global $post;
?>
<hr><?php
if (strlen($truncated_content) >= 500) {
$truncated_content = substr($truncated_content, 0, strrpos(substr($truncated_content, 0, 500), ' '));
}
?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<a href="<?php the_permalink(); ?>"><img src="<?php echo get_the_post_thumbnail_url(); ?>"></img></a></p><?php
endwhile;
}
// Posts not found
else {
echo '<h4>' . __( 'Posts not found', 'shortcodes-ultimate' ) . '</h4>';
}
?>
</div> ' . __( 'Posts not found', 'shortcodes-ultimate' ) . ''; } ?>
Avoiding Browser Plugins with KeePassXC KeePassXC is a popular free open source password manager. As…
If you've had a Gmail account for years, like I have, at some point you…
Here's a little trick I use to back up my Raspberry Pi without having to…
I try to keep my email inbox fairly clean but I do subscribe to some…
I was recently faced with the dreaded prospect of re-installing Windows 10. While the standard…
Pi-Hole and Upstream DNS Providers Pi-hole is an excellent whole-home, self-hosted ad blocker and DNS…