/    Sign up×
Community /Pin to ProfileBookmark

How to show blog posts changing every time after refreshing the page inwebsite?

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>`

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 21.2019 — Just a guess: you'll probably need to alter the query_posts() function, or create a replacement function that will use some randomizing logic in the DB query.
Copy linkTweet thisAlerts:
@shobhaauthorJun 24.2019 — @NogDog#1605213 How to do it through query?
Copy linkTweet thisAlerts:
@ginerjmJun 24.2019 — Where is the query? Is the call to wp_query doing a query for you? You will have to write your own query in that case perhaps.

Question - you have a list item holding a div holding an anchor holding a paragraph holding a string(?) and a 2nd div with a string in it. Quite a list item. Is it all necessary? You have an error in one of your style attributes too.
Copy linkTweet thisAlerts:
@shobhaauthorJun 29.2019 — How to show new posts after refreshing of page in non wordpress website not through wordpress website.
Copy linkTweet thisAlerts:
@ginerjmJun 29.2019 — Why are you repeating your question? Do you have some more code to solve this problem or for us to look at? And what do you mean by "How to do it through query"?
Copy linkTweet thisAlerts:
@shobhaauthorJun 29.2019 — The code is working properly showing post a blog website in my website but it showing the same posts everytime.

When a visitor refreshes the page it will different posts everytime.
Copy linkTweet thisAlerts:
@shobhaauthorJun 29.2019 — @ginerjm#1605570 I am asking that how to do it through wordpress query?
Copy linkTweet thisAlerts:
@ginerjmJun 29.2019 — So even tho it is NOT a wordpress script you want WP to produce a different query every time? I guess you need help from someone who knows how to work in WP!
×

Success!

Help @shobha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...