I put these in function.php
function getPostViews($postID)
{
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if ($count == '') {
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count . ' Views';
}
function setPostViews($postID)
{
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if ($count == '') {
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
} else {
$count++;
update_post_meta($postID, $count_key, $count);
}
}
// Remove issues with prefetching adding extra views
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
LiteSpeed_Cache_API::hook_tpl_esi('your_count_esi', 'hook_esi' );
function hook_esi( $param ) {
setPostViews( $param[ 'id' ] ) ;
exit;
}
and this in single php
`
<?php
echo LiteSpeed_Cache_API::esi_url( ‘your_count_esi’, ‘RezaY test’, array( ‘id’ => get_the_ID() ) ) ;
?>
<?php echo getPostViews(get_the_ID()); ?>
`
but after echo lightspeed
it shows my homepage with all of my recent post!
-
This reply was modified 7 years, 1 month ago by
RezaY.