WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: WP Super Cache] Make some parts dynamic (18 posts)

  1. Ruriko
    Member
    Posted 6 years ago #

    Is there a way to make certain parts of the page stay dynamic? cause I want to make my rotating banner dynamic

  2. Donncha O Caoimh
    Member
    Posted 6 years ago #

    The easiest way is the oldest way: use Javascript and add your banner php script to the list of rejected URLs.

  3. nebadom
    Member
    Posted 6 years ago #

    In WP-Chache and Staticize Reloaded, there is this hack:

    <!--mfunc function_name('parameter', 'another_parameter') -->
    <?php function_name('parameter', 'another_parameter') ?>
    <!--/mfunc-->

    The HTML comments around the mirrored PHP allow it to be executed in the static page. To include another file try this:

    <!--mclude file.php-->
    <?php include_once(ABSPATH . 'file.php'); ?>
    <!--/mclude-->

    -------------
    I'd like to know if that would work on WP-Super Cache. Maybe that would help to those who don't know (or don't want) to get a java app.

  4. nebadom
    Member
    Posted 6 years ago #

    Update: I want to have some "Latest Posts" in my home page, but the Wp-Super Cache prevent it to work properly (caches that too).

  5. Donncha O Caoimh
    Member
    Posted 6 years ago #

    You don't need to use Java. Use Javascript. Turn off the super cache part of the plugin (Half on), and disable compression. You can do the mclude stuff then but you lose out on staticly cached files.

  6. nebadom
    Member
    Posted 6 years ago #

    Do you know a good one for text/scroll?

  7. jimmiejo
    Member
    Posted 6 years ago #

    I'm using the Time Since plugin which displays the time for each post as "3 weeks, 1 day ago".

    WP-Super-Cache seems to cache the date on every post until the scheduled clearing time (3600 seconds). I'm not sure which of the above methods you guys mentioned would allow me to make the following function dynamic (excluded from WP-Super-Cache):

    <?php if (function_exists('time_since')) {
    					echo time_since(abs(strtotime($post->post_date_gmt . " GMT")), time()) . " ago";
    					} else {
    					the_time('F jS, Y');
    				} ?>

    Is it at all possible?

  8. Donncha O Caoimh
    Member
    Posted 6 years ago #

    jimmiejo - best to use javascript really, r shorten the cache timeout to a minute or so..

  9. jimmiejo
    Member
    Posted 6 years ago #

    Would you be able to recommend how to implement javascript with a function like the one I posted above?

    I don't have much experience with JS and am not quite sure how it could work. I'd love if you could share an example :)

  10. jimmiejo
    Member
    Posted 6 years ago #

    Think I figured it out, donncha:

    <script type="text/javascript">
    	document.write('<?php if (function_exists('time_since')) {
    		echo time_since(abs(strtotime($post->post_date_gmt . " GMT")), time()) . " ago";
    		} else {
    		the_time('F jS, Y');
    	} ?>');
    </script>

    It seems to work (haven't activated everything with wp-super-cache yet. Fingers crossed :)

  11. jimmiejo
    Member
    Posted 6 years ago #

    Hmmm.... that didn't seem to do it. When Super Cache or Half is on, it is still caching the time with the above php in javascript.

  12. Donncha O Caoimh
    Member
    Posted 6 years ago #

    Your JS will have to do the calculation instead of PHP.

  13. jimmiejo
    Member
    Posted 6 years ago #

    That's way out of my league and quite the pain for dynamic functions. Guess it's a no go for the super cache plugin.

    Thanks anyways, Donncha.

  14. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    If you really must write it in PHP, create a PHP file to do the calculation and output the HTML, then use javascript to include it into the page. This is pretty easy with jquery.

    <script type="text/javascript">
    jQuery(function($) {
    $("#contentArea").load("/whatever.php");
    }
    </script>
    <div id="contentArea">... temporary loading message ...</div>

    Just make sure that you enqueue the jquery script in your functions.php or something. Like so: wp_enqueue_script('jquery');

  15. jimmiejo
    Member
    Posted 6 years ago #

    Thanks Otto, I'll give that a try.

  16. jimmiejo
    Member
    Posted 6 years ago #

    Just an update: I noticed I have a few other dynamic functions in different sections of my site, so it's not ideal to call on everything through javascript.

    Donncha suggested earlier setting the cache expiry to a minute or so, which I've done, and seems to do the trick with a steady flow of traffic. Hopefully it's not too server intensive to cache large amounts of content so rapidly. Will have to wait and see.

    Thanks again to everyone for kindly replying.

  17. Rajesh
    Member
    Posted 6 years ago #

    there is no point in using a cache plugin to cache just for a minute or so...neither is javascript the solution either...All the advantages of wordpress (php based) is lost...guess we need to have a way to enable some server sided scripting even if a caching page is enabled...

    donncha,

    Can't the plugin provide a way to trigger other plugins(those that the user wants to run) thro. AJAX?

  18. Donncha O Caoimh
    Member
    Posted 6 years ago #

    Rajesh - AJAX is Javascript you know? :)

    It's simple to use Javascript to build a query string and display a chunk of html. There's no need for the cache to provide that.

Topic Closed

This topic has been closed to new replies.

About this Topic