Do you truly just want 10 random links to posts to display?
Try adding this to your functions.php file:
function cleancoded_random_posts() {
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'posts_per_page' => 10,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$string .= '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$string .= '<li><a href="'. get_permalink() .'">'. get_the_title() .'</a></li>';
}
$string .= '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
$string .= 'no posts found';
}
return $string;
}
add_shortcode('cleancoded-random-posts','cleancoded_random_posts');
add_filter('widget_text', 'do_shortcode');
What this is, and how it works:
This code creates a function that displays 10 random posts. It then creates a shortcode you can use to display random posts anywhere on your site (it also enables shortcodes to be executed inside WordPress widgets so that you can use this shortcode inside a text widget).
Now you can display random posts inside a WordPress post, page or text widget using the shortcode [cleancoded-random-posts]
.
And here’s a quick video walkthrough I created to show how to use this. I created a sandbox test install of WordPress, created and published some placeholder posts, added this code to my functions.php file, then added this shortcode to a widget, and show how the posts are displayed, in random order, in the sidebar:
If this is too basic, or you need more functionality, have a look at this plugin, it creates a widget, and shortcodes that are configurable with a variety of parameters to suit your needs:
https://www.ads-software.com/plugins/advanced-random-posts-widget/
For number 2, it sounds like you’re looking for an HTML sitemap plugin. There are many of these to choose from, like this one:
]]>For the first issue, adding 10 links to every page of your WordPress site, what are the business rules around what you’re looking to achieve?
For SEO.
Do you truly just want 10 random links to posts to display?
Yep.
For number 2, it sounds like you’re looking for an HTML sitemap plugin. There are many of these to choose from, like this one:
Well, I need 3 or more columns otherwise it’s gonna be too long.
]]>Here’s an (admittedly older) plugin that might work for your WordPress site:
https://www.ads-software.com/plugins/wp-seo-html-sitemap/
I’ve just tested it with WordPress 4.9.8 and it seems to provide the functionality you’re looking for, please have a look here:
]]>plugin which add 10 links (a good option if number can be configured as well) to other pages on every page (sort of ‘related’ but not really as I don’t have any categories or tags for my pages)
There are a lot of pages on site and I want them to be linked to each other.
]]>