Dynamically adding pages to Smart List- How to bust cache?

Posted in: Newspaper
Post count: 28

I’ve written a function that uses a filter to dynamically add an extra page to all of our smart list articles. The function allows me to display a promotion which comes up as the last slide in the smart list.

This has been working great and now I’d like to mix it up a little and randomly show one promotion out of a list of 4 or 5.

The problem I’ve run into is that WP Super Cache is caching the first additional slide shown and my “random” code has no effect.

Do you have any suggestions on how to bust the cache in the scenario?

Thanks!

Post count: 39

Great question! @five-40 did you write a custom code or used a plugin to achieve the embedded ad inside the smart lists? I ask because i am trying to do exactly what you did.

Post count: 28

Hi Gunnar-

Here is the code I came up with:


/*  ----------------------------------------------------------------------------
   Filter for adding additional pages to a smart list article v1.02
----------------------------------------------------------------------------- */

// We want to show an existing article as a promotion when a user clicks Next while viewing a smart list article

// NOTES FOR ARTICLES USED AS ADS/PROMOTIONS AT END OF SMART LIST:
// 1. Make the promo article a Smart List 
// 2. The first line of the article used as a promotion must start with a <h3> header

function add_promo_to_smartlist($content) {
	if(is_single()) {
	    $my_postid = 15304; // Enter ID of post to append
	    $post_object = get_post( $my_postid );
        $new_content1 = $post_object->post_content;
        
    	$content .= $new_content1;
	}	
	return $content;
}
add_filter('the_content', 'add_promo_to_smartlist');


NOTE: I have only used this with Smart List 7.

I made this into a plugin but you can also use it in your functions.php file. (Use at your own risk! I know just enough about this stuff to be dangerous.)

  • This reply was modified 10 years by five40.
  • This reply was modified 10 years by five40.
  • This reply was modified 10 years by five40.
Post count: 22421

Hello,
If you want to override the wp super cache plugin, maybe you could ask them about a method as they will know best how to do it. Or maybe you can find a solution online:
https://wordpress.org/support/topic/plugin-wp-super-cache-how-to-stop-caching-of-one-single-page
https://www.webhostinghero.com/recommended-settings-for-wp-super-cache-beginners/
https://wordpress.org/support/topic/plugin-wp-super-cache-exclude-specific-pages
I hope this helps.
Thanks.

Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.