Skip to content

Instantly share code, notes, and snippets.

@el-rotny
Last active January 11, 2018 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save el-rotny/8678b4286c519dddc204443ec52f91fb to your computer and use it in GitHub Desktop.
Save el-rotny/8678b4286c519dddc204443ec52f91fb to your computer and use it in GitHub Desktop.
Cache Comment List for Disqus
<?php
/*
* Adds Author Box Extending Qode
*
*/
// Allow HTML in author bio section
function abtw_comment_cache(){
$cache_key = '_abtw_comment-cache-key';
$cache = get_post_meta( $post->ID, $cache_key, true );
// if ( empty( $cache ) || $cache['expires'] < time() ):
ob_start();
?>
<!-- // A Simplified version of wp-content/plugins/disqus-comment-system/comments.php -->
<?php if(is_plugin_active('disqus-comment-system/disqus.php')): ?>
<?php if (have_comments()): ?>
<div id="dsq-content">
<?php if (get_comment_pages_count() > 1 && get_option('page_comments')): // Are there comments to navigate through? ?>
<div class="navigation">
<div class="nav-previous">
<span class="meta-nav">&larr;</span>&nbsp;
<?php previous_comments_link( dsq_i('Older Comments')); ?>
</div>
<div class="nav-next">
<?php next_comments_link(dsq_i('Newer Comments')); ?>
&nbsp;<span class="meta-nav">&rarr;</span>
</div>
</div> <!-- .navigation -->
<?php endif; // check for comment navigation ?>
<ul id="dsq-comments">
<?php
/* Loop through and list the comments. Tell wp_list_comments()
* to use dsq_comment() to format the comments.
*/
wp_list_comments(array('callback' => 'dsq_comment'));
?>
</ul>
<?php if (get_comment_pages_count() > 1 && get_option('page_comments')): // Are there comments to navigate through? ?>
<div class="navigation">
<div class="nav-previous">
<span class="meta-nav">&larr;</span>
&nbsp;<?php previous_comments_link( dsq_i('Older Comments') ); ?>
</div>
<div class="nav-next">
<?php next_comments_link( dsq_i('Newer Comments') ); ?>
&nbsp;<span class="meta-nav">&rarr;</span>
</div>
</div><!-- .navigation -->
<?php endif; // check for comment navigation ?>
</div>
<?php endif; ?>
<?php else: // If plugin isn't active ?>
<ul class="comment-list">
<?php wp_list_comments(array( 'callback' => 'qode_comment')); ?>
</ul>
<div class="comment_pager">
<p><?php paginate_comments_links(); ?></p>
</div>
<?php endif; ?>
<?php
$data = ob_get_contents();
ob_end_clean();
$encoded_data = base64_encode($data);
$cache = array(
'expires' => time() + 24 * HOUR_IN_SECONDS,
'data' => $encoded_data,
);
update_post_meta( $post->ID, $cache_key, $cache );
// endif;
echo base64_decode($cache['data']); // cached or uncached result
}
@el-rotny
Copy link
Author

NOTE, you need to put this into a function obviously and output the content underneath <?php comments_template('', true); ?> in wp-content/themes/bridge-child/single.php

@el-rotny
Copy link
Author

Ian we might need to seriablize this object before we save it. Not sure this is untested btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment