I have made a page in non-wordpress website which is showing the post from blog of wordpress website, it is working properly. I have added some PHP code in my page. Now I want that every time I refresh the page it will show different different post every time.
<?php
define('WP_USE_THEMES', false);
require('blog/wp-load.php');
query_posts('showposts=4');
?>
<ul style="margin-top:0px">
<?php while (have_posts()): the_post(); ?>
<li style="border: 1px solid #edf4fc;margin-bottom:30px">
<div class="img-hover-zoom">
<a target="_blank" href="<?php the_permalink(); ?>"><p>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</p>
<div class="content">
<h4 style="font-size:18px;font-weight:500;"><?php the_title(); ?></h4>
</div>
</a></div>
</li>
<?php endwhile; ?>
</ul>```
It is showing 5 post but I want to show 5 random post.
I have made a page in non-wordpress website which is showing the post from blog of wordpress website, it is working properly. I have added some PHP code in my page. Now I want that every time I refresh the page it will show different different post every time.
<?php
define('WP_USE_THEMES', false);
require('blog/wp-load.php');
query_posts('showposts=4');
?>
<ul style="margin-top:0px">
<?php while (have_posts()): the_post(); ?>
<li style="border: 1px solid #edf4fc;margin-bottom:30px">
<div class="img-hover-zoom">
<a target="_blank" href="<?php the_permalink(); ?>"><p>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</p>
<div class="content">
<h4 style="font-size:18px;font-weight:500;"><?php the_title(); ?></h4>
</div>
</a></div>
</li>
<?php endwhile; ?>
</ul>```
It is showing 5 post but I want to show 5 random post.
Share
Improve this question
asked Jul 1, 2019 at 6:08
Shobha PatwalShobha Patwal
13 bronze badges
0
1 Answer
Reset to default 1This line is responsible for posts that are showing:
query_posts('showposts=4');
All you tell in it is “take 4 posts” and WP will take 4 most recent posts, because that’s the default behavior.
If you want to take random posts, you have to tell WP to order posts randomly:
query_posts( array(
'posts_per_page' => 4,
'orderby' => 'rand'
) );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745355073a4624065.html
评论列表(0条)