简体   繁体   中英

Dynamic content in PHP Wordpres page

I have a ecommerce store website running with Wordpress. I'd like to include a section with a -random custormer's product review, so that every time someone access the page, there will be a different comment there. I'm not used to PHP, but I managed to create a shortcode which takes a random comment and returns the proper HTML. It is working fine (in eddition mode, every time I insert the shortcode a different comment appears). My issue is that when I leave the page and return, the previous one is still there. I believe that it is being caused by cache, but I wouldn't like to disable the cache for the whole page. How you I force the shortcode run again (I don't know if it is the right way to explain) and make sure that at every access, a different comment appears? One solution I thought is to have JS code which would do preaty much the same thing my PHP code does, using Woocommerce API to get the data. But I'm wondering if there is a simpler solution to do that, like forcing the specific section not being cached or re-run the shortcode.

Thanks!

JS can't do what PHP does here: at most it can create an AJAX-call to the backend that then runs a query for a random comment and returns it. You need to render it thereafter. It's fairly standard, but overkill for your case.

Instead, you're going to want to check whether your caching mechanism supports ESI or something else that excluded parts of your code from being cached.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM