D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
sadaunjx
/
public_html
/
wp-content
/
themes
/
newsplus1
/
inc
/
Filename :
functions-posts.php
back
Copy
<?php /* Copyrights (C) Arb4Host Network */ ?> <?php add_action('get_template_part_archive-loop', function() { if ( in_the_loop() ) { set_query_var('posts_current_post', $GLOBALS['wp_query']->current_post + 1); set_query_var('posts_widget_args', false); set_query_var('posts_posts_args', false); set_query_var('posts_posts_style', apply_filters('a4h_filter_archive_style', a4h_options('archive_style'))); } }); function a4h_get_post_terms($taxonomy = false, $post_id = false) { global $post; $post_id = $post_id ? $post_id : $post->ID; $taxonomies = get_post_taxonomies($post_id); if ( !$taxonomies ) { return; } $taxonomy = $taxonomy ? $taxonomy : $taxonomies[0]; $taxonomy = apply_filters('a4h_filter_post_taxonomy', $taxonomy, $taxonomies, $post_id); $terms = wp_get_post_terms($post_id, $taxonomy); if ( $terms && !is_wp_error($terms) ) { return $terms; } return false; } function a4h_get_post_terms_ids($taxonomy = false, $post_id = false) { $terms = a4h_get_post_terms($taxonomy, $post_id); $ids = array(); if ( $terms ) { foreach ( $terms as $term ) { $ids[] = $term->term_id; } } return $ids; } function a4h_get_current_term_id($taxonomy = false, $post_id = false) { $term = ''; if ( is_singular() ) { $terms = a4h_get_post_terms($taxonomy, $post_id); if ( $terms ) { $term = $terms[0]->term_id; } } else { $term = get_queried_object_id(); } return $term; } function a4h_get_post_types_by_taxonomy($tax) { $output = array(); $post_types = get_post_types(); foreach ( $post_types as $post_type ) { $taxonomies = get_object_taxonomies($post_type); if ( in_array($tax, $taxonomies) ) { $output[] = $post_type; } } return $output; } function a4h_post_args_taxonomies_output($instance_tax, $taxonomy = 'category') { $instance_tax = (array)$instance_tax; $taxonomies = array(); $object_id = get_queried_object_id(); if ( empty($instance_tax) ) { return $taxonomies; } if ( in_array('all', $instance_tax) ) { return $taxonomies; } if ( in_array('current', $instance_tax) ) { if ( is_single() ) { $post_terms = a4h_get_post_terms_ids($taxonomy); $taxonomies[] = array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $post_terms); return $taxonomies; } else if ( is_page() ) { return $taxonomies; } else if ( is_category() ) { $taxonomies[] = array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $object_id); return $taxonomies; } else { return $taxonomies; } } $taxonomies[] = array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $instance_tax); return $taxonomies; } function a4h_widget_title_link_to_category($title, $instance = array()) { if ( empty($instance['title']) || empty($instance['cat_link']) || empty($instance['cats']) ) { return $title; } $categories = get_the_category(); $category_id = $categories[0]->cat_ID; $cat_id = in_array('current', $instance['cats']) ? $category_id : $instance['cats'][0]; $cat_link = get_category_link($cat_id); return sprintf('<a class="widget-cat-link" href="%1$s">%2$s</a>', $cat_link, $title); } add_filter('widget_title', 'a4h_widget_title_link_to_category', 10, 2); function a4h_post_meta_item($meta = '', $prefix = '', $postfix = '', $echo = true) { global $post; if ( !$meta ) { return; } $default_prefix = a4h_filter_post_meta_item_prefix($meta); $prefix = apply_filters('a4h_filter_post_meta_item_prefix', $default_prefix, $meta); $meta_content = ''; if ( $meta == 'published' || $meta == 'updated' ) { $meta_content = '<a rel="bookmark" href="'.get_permalink().'" title="'.__('Posted on', THEME_TEXT_DOMAIN).': '.get_the_time('j F Y - g:ia').' / '.__('Last Updated', THEME_TEXT_DOMAIN).': '.get_the_modified_time('j F Y - g:ia').'">'.a4h_post_time().'</a>'; } if ( $meta == 'author' ) { $meta_content = '<span class="author vcard"><a class="url fn n" href="'.esc_url(get_author_posts_url(get_the_author_meta('ID', $post->post_author))).'" title="'.sprintf(__('All posts by: %s', THEME_TEXT_DOMAIN), get_the_author_meta('display_name', $post->post_author)).'">'.get_the_author_meta('display_name', $post->post_author).'</a></span>'; } if ( $meta == 'views' && function_exists('the_views') && apply_filters('a4h_filter_post_views_case', true) ) { $meta_content = a4h_get_views_number(); } if ( $meta == 'comments' ) { $meta_content = a4h_get_comments_number(); } if ( $meta == 'taxonomies' ) { $terms = a4h_get_post_terms(); if ( $terms ) { foreach ( $terms as $term ) { $terms_list[] = '<a href="'.get_term_link($term).'" rel="tag">'.$term->name.'</a>'; $meta_content = implode(apply_filters('a4h_filter_taxonomies_sep', '<span class="sep"> - </span>'), $terms_list); } } } if ( $meta == 'taxonomy' ) { $terms = a4h_get_post_terms(); if ( $terms ) { $term = $terms[0]; $meta_content = '<a href="'.get_term_link($term).'" rel="tag">'.$term->name.'</a>'; } } $meta_prefix = $prefix ? sprintf('<span class="meta-item-prefix">%1$s</span> ', $prefix).' ' : ''; $meta_content = $meta_content ? sprintf('<span class="meta-item-content">%1$s</span>', $meta_content) : ''; $meta_postfix = $postfix ? ' '.sprintf('<span class="meta-item-postfix">%1$s</span>', $postfix) : ''; $output = $meta_content ? sprintf('<span class="meta-item meta-%1$s">%2$s%3$s%4$s</span>', $meta, $meta_prefix, $meta_content, $meta_postfix) : ''; if ( $echo ) { echo $output; } else { return $output; } } function a4h_terms_list($widget_args = array(), $terms_args = array()) { $style = !empty($widget_args['style']) ? $widget_args['style'] : 'style1'; $terms_args['use_desc_for_title'] = false; $terms_args = apply_filters('a4h_filter_taxonomies_list_args', $terms_args, $widget_args); $show_count = !empty($terms_args['show_count']) ? 'show-count' : ''; $terms_list = wp_list_categories($terms_args); $terms_list = str_replace('(', '<div class="title-font count"><span class="number">', $terms_list); $terms_list = str_replace(')', '</span></div>', $terms_list); $terms_list = preg_replace('/<a (.*?)>(.*?)<\/a>/', '<a $1 ><h3 class="title">$2</h3></a>', $terms_list); if ( $terms_list ) { echo '<div class="terms '.$style.' '.$show_count.'">'; echo '<div class="terms-inner">'; echo '<ul class="d-flex flex-wrap">'; echo $terms_list; echo '<li class="dummy"></li><li class="dummy"></li><li class="dummy"></li><li class="dummy"></li><li class="dummy"></li><li class="dummy"></li>'; echo '</ul>'; echo '</div>'; echo '</div>'; } } function a4h_posts_list($widget_args = array(), $posts_args = array(), $_this = false) { global $post; $main_style = !empty($widget_args['style']) ? $widget_args['style'] : 'style1'; $slider = !empty($widget_args['style']) && strpos($widget_args['style'], 'slider') !== false ? 'slider' : ''; $posts_args['post_status'] = 'publish'; $posts_args = apply_filters('a4h_filter_posts_list_args', $posts_args, $widget_args); $posts_list = new WP_Query($posts_args); do_action('a4h_hook_posts_list_before', $widget_args, $posts_args); if ( $posts_list->have_posts() ) { echo '<div class="posts '.$slider.' '.$main_style.'">'; echo '<div class="posts-inner">'; $i = 0; while ( $posts_list->have_posts() ) : $posts_list->the_post(); $i++; $style = apply_filters('a4h_filter_posts_list_post_style', $main_style, $widget_args, $posts_args, $i); set_query_var('posts_current_post', $i); set_query_var('posts_widget_args', $widget_args); set_query_var('posts_posts_args', $posts_args); set_query_var('posts_posts_style', $style); do_action('a4h_hook_posts_loop_start', $widget_args, $posts_args, $i); get_template_part('archive-loop'); do_action('a4h_hook_posts_loop_end', $widget_args, $posts_args, $i); endwhile; wp_reset_postdata(); echo '</div>'; echo '</div>'; a4h_posts_list_slider($widget_args, $posts_args, $_this); } else { echo '<p class="no-content py-3">'.__('Nothing Found', THEME_TEXT_DOMAIN).'</p>'; } do_action('a4h_hook_posts_list_after', $widget_args, $posts_args); } function a4h_posts_list_slider($widget_args, $posts_args, $_this) { do_action('a4h_posts_list_slider_function', $widget_args, $posts_args, $_this); if ( strpos($widget_args['style'], 'slider') === false ) { return; } wp_enqueue_script('owl-carousel'); wp_enqueue_script('owl-carousel-thumbs'); ?> <script> jQuery(document).ready(function($) { var owl = $('#<?php echo $_this->id; ?> .posts-inner'); owl.owlCarousel({ rtl: true, thumbs: true, thumbImage: false, thumbsPrerendered: true, thumbItemClass: 'owl-thumb', autoplay: true, loop: true, nav: true, navText: '', onInitialize: onInitialize, onInitialized: onInitialized, <?php if ( strpos($widget_args['style'], 'slider1') !== false ) { ?> responsiveBaseElement: $('#<?php echo $_this->id; ?> .posts'), responsive: {0:{items:1,},470:{items:2,},715:{items:3,},960:{items:4,},1205:{items:5,},1450:{items:6,}}, <?php } ?> <?php if ( strpos($widget_args['style'], 'slider1') === false ) { ?> smartSpeed: 0, items: 1, <?php } ?> <?php do_action('a4h_posts_list_widget_slider_options', $widget_args, $posts_args, $_this); ?> }); function onInitialize(event) { owl.parents('.slider').show(); owl.attr('data-slider-id', '<?php echo $_this->id; ?>'); owl.after('<div class="clearfix owl-thumbs" data-slider-id="<?php echo $_this->id; ?>"></div>'); $.each(owl.find('.post'), function(i) { var link = $(this).find('a').attr('href'); var title = $(this).find('.title-inner').text(); owl.parents('.slider').find($('.owl-thumbs')).append('<a class="owl-thumb" href="' + link +'"><h3 class="title">' + title +'</h3></a>'); }); } function onInitialized(event) { owl.find('.owl-item, .owl-stage').addClass('d-flex flex-grow-children'); } }); </script> <?php } class a4h_posts_list_custom_styles_filters { function init() { add_filter('a4h_filter_posts_list_post_style', array($this, 'style'), 10, 4); add_filter('a4h_filter_posts_list_post_thumb_size', array($this, 'thumb_size'), 10, 4); add_action('a4h_hook_posts_list_post_inner_end', array($this, 'inner_end'), 10, 3); } function style($main_style, $widget_args, $posts_args, $i) { $custom_styles = a4h_posts_list_custom_styles(); foreach ( $custom_styles as $custom_style ) { if ( !empty($custom_style['post_class']) ) { foreach ( $custom_style['post_class'] as $index => $value ) { if ( in_array($widget_args['style'], explode(',', $custom_style['style']) ) ) { if ( in_array($i, explode(',', $index)) || array_key_exists('any', $custom_style['post_class']) ) { return $value; } } } } } return $main_style; } function thumb_size($default, $widget_args, $posts_args, $i) { $custom_styles = a4h_posts_list_custom_styles(); foreach ( $custom_styles as $custom_style ) { if ( !empty($custom_style['thumb_size']) ) { foreach ( $custom_style['thumb_size'] as $index => $value ) { if ( in_array($widget_args['style'], explode(',', $custom_style['style']) ) ) { if ( in_array($i, explode(',', $index)) || array_key_exists('any', $custom_style['thumb_size']) ) { return $value; } } } } } return $default; } function inner_end($widget_args, $posts_args, $i) { $custom_styles = a4h_posts_list_custom_styles(); foreach ( $custom_styles as $custom_style ) { if ( !empty($custom_style['inner_end']) ) { foreach ( $custom_style['inner_end'] as $index => $value ) { if ( in_array($widget_args['style'], explode(',', $custom_style['style']) ) ) { if ( in_array($i, explode(',', $index)) || array_key_exists('any', $custom_style['inner_end']) ) { call_user_func($value, $widget_args, $posts_args, $i); } } } } } } } function a4h_posts_list_custom_styles() { $custom_styles = array(); $custom_styles[] = array('style' => 'slider1', 'post_class' => array('any' => 'style2')); $custom_styles[] = array('style' => 'slider2,slider3,slider4', 'post_class' => array('any' => 'style3 xl-font'), 'thumb_size' => array('any' => '800x600')); $custom_styles[] = array('style' => 'grid1', 'post_class' => array('1' => 'style3 cols2 rows2 xl-font', '2' => 'style3 cols2 lg-font', implode(',', range(3,100)) => 'style3'), 'thumb_size' => array('1,2' => '800x600')); $custom_styles[] = array('style' => 'grid2', 'post_class' => array('1' => 'style3 cols2 rows2 xl-font', implode(',', range(2,100)) => 'style3'), 'thumb_size' => array('1' => '800x600')); $custom_styles[] = array('style' => 'grid3', 'post_class' => array('1,2' => 'style3 cols2 rows2 xl-font xl-image', implode(',', range(3,100)) => 'style3'), 'thumb_size' => array('1,2' => '800x600')); $custom_styles[] = array('style' => 'grid4', 'post_class' => array('1' => 'style3 colsx xl-font xl-image', implode(',', range(2,100)) => 'style3'), 'thumb_size' => array('1' => 'full')); $custom_styles[] = array('style' => 'grid5', 'post_class' => array('1' => 'style3 colsx lg-font', implode(',', range(2,100)) => 'style1'), 'thumb_size' => array('1' => '500x300')); $custom_styles[] = array('style' => 'grid6', 'post_class' => array('1' => 'style3 colsx xl-font lg-image', implode(',', range(2,100)) => 'style2'), 'thumb_size' => array('1' => '500x300')); $custom_styles[] = array('style' => 'grid7', 'post_class' => array('1' => 'style3 cols2 rows2 xl-font', implode(',', range(2,100)) => 'style1'), 'thumb_size' => array('1' => '800x600')); $custom_styles[] = array('style' => 'grid8', 'post_class' => array('1' => 'style3 cols2 rows2 xl-font', implode(',', range(2,100)) => 'style2'), 'thumb_size' => array('1' => '800x600')); return apply_filters('a4h_filter_posts_list_custom_styles', $custom_styles); } function a4h_posts_list_custom_styles_filters() { $class = new a4h_posts_list_custom_styles_filters(); $class->init(); } add_action('after_setup_theme', 'a4h_posts_list_custom_styles_filters');