Sindbad~EG File Manager
<?php
/*
* Security : blocking direct access
* Source : http://codex.wordpress.org/Theme_Development#Template_Files
*/
defined('ABSPATH') or die("Access Restricted");
/*
* Related Post (AMP)
*
* Returns a new WP_Query with related posts.
* https://wordpress.org/themes/expound/
*
*/
function mwp_get_related_posts_amp($postid) {
$today = getdate();
$post_count = mwp_option('amp-related-postcount');
$post_by_date = mwp_option('amp-related-postdate');
if (!empty($post_count)) {
$posts_number = $post_count;
} else {
$posts_number = 3;
}
/*
* Related by CATEGORY
*/
if (mwp_option('amp-related-post-type') == 1) :
$posts_array = get_the_category($postid);
$posts_ids = array();
foreach($posts_array as $individual_posts)
$posts_ids[] = $individual_posts->term_id;
if ($post_by_date == 1) {
$param = array(
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $posts_ids,
'post__not_in' => array($postid),
'date_query' => array(
array(
'year' => date( 'Y' )
)
),
'orderby' => 'rand',
'posts_per_page' => $posts_number,
'no_found_rows' => true,
'ignore_sticky_posts' => 1
);
} elseif ($post_by_date == 2) {
$param = array(
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $posts_ids,
'post__not_in' => array($postid),
'date_query' => array(
array(
'year' => date( 'Y' ),
'month' => $today['mon']
),
),
'orderby' => 'rand',
'posts_per_page' => $posts_number,
'no_found_rows' => true,
'ignore_sticky_posts' => 1
);
} elseif ($post_by_date == 3) {
$param = array(
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $posts_ids,
'post__not_in' => array($postid),
'year' => strftime( '%Y' ),
'week' => strftime( '%U' ),
'orderby' => 'rand',
'posts_per_page' => $posts_number,
'no_found_rows' => true,
'ignore_sticky_posts' => 1
);
} else {
$param = array(
'post_type' => 'post',
'post_status' => 'publish',
'category__in' => $posts_ids,
'post__not_in' => array($postid),
'orderby' => 'rand',
'posts_per_page' => $posts_number,
'no_found_rows' => true,
'ignore_sticky_posts' => 1
);
}
return new wp_query($param);
/*
* Related by TAGS
*/
elseif (mwp_option('amp-related-post-type') == 2) :
$posts_array = wp_get_post_tags($postid);
$posts_ids = array();
foreach($posts_array as $individual_posts)
$posts_ids[] = $individual_posts->term_id;
if ($post_by_date == 1) {
$param = array(
'post_type' => 'post',
'post_status' => 'publish',
'tag__in' => $posts_ids,
'post__not_in' => array($postid),
'date_query' => array(
array(
'year' => date( 'Y' )
),
),
'posts_per_page' => $posts_number,
'no_found_rows' => true,
'ignore_sticky_posts' => 1
);
} elseif ($post_by_date == 2) {
$param = array(
'post_type' => 'post',
'post_status' => 'publish',
'tag__in' => $posts_ids,
'post__not_in' => array($postid),
'date_query' => array(
array(
'year' => date( 'Y' ),
'month' => $today['mon']
),
),
'posts_per_page' => $posts_number,
'no_found_rows' => true,
'ignore_sticky_posts' => 1
);
} elseif ($post_by_date == 3) {
$param = array(
'post_type' => 'post',
'post_status' => 'publish',
'tag__in' => $posts_ids,
'post__not_in' => array($postid),
'year' => strftime( '%Y' ),
'week' => strftime( '%U' ),
'posts_per_page' => $posts_number,
'no_found_rows' => true,
'ignore_sticky_posts' => 1
);
} else {
$param = array(
'post_type' => 'post',
'post_status' => 'publish',
'tag__in' => $posts_ids,
'post__not_in' => array($postid),
'posts_per_page' => $posts_number,
'no_found_rows' => true,
'ignore_sticky_posts' => 1
);
}
return new wp_query($param);
/*
* YARPP Plugin
*/
elseif (mwp_option('amp-related-post-type') == 3) :
$limit = get_option('yarpp');
// Support for the Yet Another Related Posts Plugin
if ( function_exists( 'yarpp_get_related' ) ) {
$related = yarpp_get_related( array( 'limit' => $posts_number ), $postid );
return new WP_Query( array(
'post__in' => wp_list_pluck( $related, 'ID' ),
'posts_per_page' => $posts_number,
'ignore_sticky_posts' => true,
'post__not_in' => array( $postid ),
'no_found_rows' => true,
) );
}
endif;
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists