function hocwp_query($args = array()) { if (!isset($args['post_type'])) { $args['post_type'] = 'post'; } if (!isset($args['paged']) && isset($_REQUEST['paged'])) { $args['paged'] = hocwp_get_paged(); } $defaults = array('order' => 'desc', 'orderby' => 'date'); $args = wp_parse_args($args, $defaults); $cache = isset($args['cache']) ? $args['cache'] : false; if (false !== $cache) { $transient_name = hocwp_build_transient_name('hocwp_query_cache_%s', $args); if (false === ($query = get_transient($transient_name))) { $query = new WP_Query($args); if ($query->have_posts()) { if (!is_numeric($cache)) { $cache = WEEK_IN_SECONDS; } set_transient($transient_name, $query, $cache); } } return $query; } return new WP_Query($args); }
function hocwp_replace_text_placeholder($text) { remove_filter('hocwp_replace_text_placeholder', 'hocwp_replace_text_placeholder'); $text = apply_filters('hocwp_replace_text_placeholder', $text); add_filter('hocwp_replace_text_placeholder', 'hocwp_replace_text_placeholder'); $text_placeholders = array('%DOMAIN%', '%CURRENT_YEAR%', '%PAGED%', '%HOME_URL%', '%SITE_NAME%'); $text_placeholders = apply_filters('hocwp_text_placeholders', $text_placeholders); $placeholder_replace = array(hocwp_get_domain_name(home_url()), date('Y'), hocwp_get_paged(), home_url('/'), get_bloginfo('name')); $placeholder_replace = apply_filters('hocwp_text_placeholders_replace', $placeholder_replace); $text = str_replace($text_placeholders, $placeholder_replace, $text); return $text; }
<div class="<?php hocwp_wrap_class(); ?> "> <?php hocwp_breadcrumb(); hocwp_theme_site_main_before(); if (is_page()) { echo hocwp_wrap_tag(get_the_title(), 'h1', 'page-title entry-title'); } $args = array('post_type' => 'post', 'paged' => hocwp_get_paged()); $query = hocwp_query($args); if ($query->have_posts()) { echo '<div class="loop-posts">'; while ($query->have_posts()) { $query->the_post(); hocwp_theme_get_loop('post'); } wp_reset_postdata(); echo '</div>'; hocwp_pagination(array('query' => $query)); } else { hocwp_theme_get_content_none(); } hocwp_theme_site_main_after(); get_sidebar('secondary'); ?> </div>
function hocwp_is_last_paged($query = null, $paged = '') { if (empty($paged)) { $paged = hocwp_get_paged(); } $total_page = hocwp_get_last_paged($query); if ($paged == $total_page) { return true; } return false; }