How to cache widget content for each WordPress post?
-
Hello,
I’m trying to add this PHP widget to my website, the aim of the widget is to show randomly 3 other articles from my WordPress website.
<?php query_posts('showposts=3&orderby=rand'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <li><b><a>"><?php the_title(); ?></a></b><br><br> <p><?php global $post; $excerpt = $post->post_excerpt; if($excerpt==''){$excerpt = get_the_content('');} echo wp_html_excerpt(strip_shortcodes($excerpt),100); ?>...</p></li> <?php endwhile; endif; ?>
I’m using Enhanced Text Widget to insert this PHP code in a WordPress widget.
In order to reduce the use of resources, I decided to cache the content of this widget.
I’m currently using WP Fastest Cache to achieve this result.
The problem is that the widget content is cached for all posts in a regular interval of time, so the same random articles are showed in all my posts.
My objective is to show different random articles in each post. I’m looking for a technic that make the widget content cached for each post the first time the post page is loaded by a browser.
Do you have any idea on how to achieve this objective?
Thank you in advance.
- The topic ‘How to cache widget content for each WordPress post?’ is closed to new replies.