Support » Plugin: W3 Total Cache » Do not cache “Suggested Posts”

  • Resolved greendroid

    (@greendroid)


    Hi,
    after every post I have a shortcode which is showing 3 other posts on which the visitor can click to get some more related information.
    These articles are cached, so if the user reloads the page everytime the same suggested posts are shown.
    Is it somehow possible to exclude just this shortcode from page caching or do I have to disable the caching for the complete post?

    I want, that the visitor is always getting different suggested posts when the side is reloaded (e.g. via F5).
    In the “Link to the page you need help with:” an example link is stated.

    Thanks and best regards
    Greendroid

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @greendroid

    Thank you for your inquiry and I am happy to assist you with this.
    The problem obviously is that the widget which should be dynamic is cached. I am not sure if you are using any plugin for this but there are three solutions for this.

    1. The widget should be fired with an ajax call. This would ensure that it bypasses the cache and does not depend on a fact that the page is cached or not. This is something that needs to be done in the development of the widget plugin you are using or handled programmatically.

    2. Use Page Fragment cache. Page Fragment cache can be used in W3 Total Cache to exclude specific parts of the page from being cached. You can check out more details about Page Fragment Cache in our FAQ page and make sure to check out this topic where everything is explained.

    3. The last thing you can do is of course to exclude that page from being cached which is not a huge problem if you have one page to exclude, however, if the widget is on every post that means that Page caching would no longer have an effect on any of those posts when excluded from cache.
    I hope this helps!
    Thanks!

    Thread Starter greendroid

    (@greendroid)

    Hi,
    thanks for your support. I think number 2 is best fitting for me.
    I tried out the FAQ and the topic you have mentioned, but I am stuck now.

    I am using a function.php action to hook into each postpage:

    <?php
    add_action('comment_form_before', 'add_next_articles');
    function add_next_articles() 
    {
    ...
    $nextArticleShortcode .= " cols=3 excerpt_length=40 more_msg=\"Weiterlesen...\" orderby=rand posts_per_page=3 show=excerpt hide_bottom_info=true]";
    $commenter = wp_get_current_commenter();
    echo '<p class="commentnotice"><h3>Weitere Artikel zu dem Thema:</h3><br>' .do_shortcode($nextArticleShortcode) .'<br></p>';
    }
    ?>
    

    Within this function I am creating a shortcode string call, which I am then executing via do_shortcode to get the correct html content at the correct location on my blogpage.
    This shortcode is creating a small “gallery” with some next articles which can be clicked.

    How do I insert <!-- mfunc mysecurestring --> and <!-- /mfunc mysecurestring --> in the function.php? If I just replace the <?php and ?> with the strings before I get an error on my webpage.
    I also tried to include it into the echo line just as plain text, but then the webpage is not loading at all anymore. I just get a white screen.

    Thanks and kind regards
    Greendroid

    • This reply was modified 1 year, 3 months ago by greendroid. Reason: Added some more code as an example
    • This reply was modified 1 year, 3 months ago by greendroid. Reason: Added some more code as an example
    • This reply was modified 1 year, 3 months ago by greendroid.
    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @greendroid

    This is a Page Fragment Cache feature that works on a specific page.
    In your case, it would be best to use ajax call for this function to bypass the cache.
    Thanks!

    Thread Starter greendroid

    (@greendroid)

    Hi,
    thanks for your support.
    Unfortunately I do not have any influence how the plugin is handling is accesses. I cannot change the behavior of the plugin.

    Is there a way how I can exclude this shortcode execution, as it is currently, from the caching?

    Thanks and kind regards
    Greendroid

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @greendroid

    Thank you for the information.
    Can you please share which plugin you are using for this?
    As you can see in the FAQ:

    The comment/code blocks should be added to your theme template files as HTML and not within the PHP open (<?php) and close (?>) tags, as it will cause a PHP parse error/syntax error. Do not include any sensitive information in your code fragments; the code can be revealed if W3 Total Cache is deactivated, the Page Cache is changed to use an incompatible storage engine, or the defined W3TC_DYNAMIC_SECURITY string value is changed or not defined.

    Since it’s loading on every page, this is I would advise you to reach out to the support of the plugin you are using for this so they can provide you with the solution for caching compatibility. The best way to do this is with the ajax call.
    Thanks!

    Thread Starter greendroid

    (@greendroid)

    Hi,
    thanks for your support.
    Exactly, this was the point which I do not understand. I cannot/don’t want to change the theme files appropriatly. I don’t have the knowledge for it 😀

    The plugin I am using is:
    Weaver Show Post: https://de.wordpress.org/plugins/show-posts/

    I will open a ticket in the support forum of this plugin. Perhaps they can help.
    Thanks and kind regards
    Greendroid

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @greendroid

    Thank you for the information.
    Yes, it would be the best idea to check with them about the support with the caching plugins.
    Thanks!

    Thread Starter greendroid

    (@greendroid)

    Hi!
    Unfortunately there will be no support with an ajax-call or something similar to prevent the caching of the post-preview from the plugin-support.
    So I expect, that there is no possbility for me to exclude the “Recommended posts” from the caching, right? Without disabling the caching completely for this site?
    Thanks and kind regards
    Greendroid

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @greendroid

    The only way is with the Page Fragment caching.
    And the information you got from the other plugin is suggesting that either they have some of their caching solutions that may be compatible with this plugin or they just do not care about their users.
    The plugin you are using has only 10000 installs, so you may want to check some other solution for this.
    Thanks!

    Thread Starter greendroid

    (@greendroid)

    Hi,
    I like the plugin, it is working very stable and is doing what I want.
    Therefore I don’t want to change the plugin necessarily.

    Can you give a little bit more support in how I would have to implement the Page Fragment Caching?

    Thanks and kind regards
    Greendroid

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Do not cache “Suggested Posts”’ is closed to new replies.