ID);
if ($morenews_post_categories) {
$morenews_output = '
';
$category_count = 0;
foreach ($morenews_post_categories as $post_category) {
$morenews_t_id = $post_category->term_id;
$morenews_color_id = "category_color_" . $morenews_t_id;
// retrieve the existing value(s) for this meta field. This returns an array
$morenews_term_meta = get_option($morenews_color_id);
$morenews_color_class = ($morenews_term_meta) ? $morenews_term_meta['color_class_term_meta'] : 'category-color-1';
$morenews_output .= '-
' . esc_html($post_category->name) . '
';
if ($morenews_is_single == false) {
if (++$category_count == $show_category_number) break;
}
}
$morenews_output .= '
';
echo wp_kses_post($morenews_output);
}
}
}
endif;
if (!function_exists('morenews_get_category_color_class')) :
function morenews_get_category_color_class($term_id)
{
$morenews_color_id = "category_color_" . $term_id;
// retrieve the existing value(s) for this meta field. This returns an array
$morenews_term_meta = get_option($morenews_color_id);
$morenews_color_class = ($morenews_term_meta) ? $morenews_term_meta['color_class_term_meta'] : '';
return $morenews_color_class;
}
endif;
if (!function_exists('morenews_post_item_meta')) :
function morenews_post_item_meta($morenews_post_display = 'spotlight-post')
{
global $post;
if ('post' == get_post_type($post->ID)) :
$morenews_author_id = $post->post_author;
$morenews_date_display_setting = morenews_get_option('global_date_display_setting');
$morenews_author_icon_gravatar_display_setting = morenews_get_option('global_author_icon_gravatar_display_setting');
if ($morenews_post_display == 'list-post') {
$morenews_post_meta = morenews_get_option('list_post_date_author_setting');
} elseif ($morenews_post_display == 'grid-post') {
$morenews_post_meta = morenews_get_option('small_grid_post_date_author_setting');
} else {
$morenews_post_meta = morenews_get_option('global_post_date_author_setting');
}
if ($morenews_post_meta == 'show-date-only') {
$morenews_display_author = false;
$morenews_display_date = true;
} elseif ($morenews_post_meta == 'show-author-only') {
$morenews_display_author = true;
$morenews_display_date = false;
} elseif (($morenews_post_meta == 'show-date-author')) {
$morenews_display_author = true;
$morenews_display_date = true;
} else {
$morenews_display_author = false;
$morenews_display_date = false;
}
?>
';
the_time($date_format); // This outputs the formatted date
// echo '';
} else {
$time_ago = human_time_diff(get_the_time('U'), current_time('timestamp'));
$time_ago_text = sprintf(__('Posted on %s %s', 'morenews'), $time_ago, __('ago', 'morenews'));
// echo '';
echo esc_html($time_ago_text);
// echo '';
}
?>
' . esc_html('Tags: %1$s') . '', $tags_list);
}
}
}
if (is_single()) {
edit_post_link(
sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers */
__('Edit %s', 'morenews'),
array(
'span' => array(
'class' => array(),
),
)
),
get_the_title()
),
'',
''
);
}
}
endif;
if (!function_exists('morenews_preload_header_image')) :
function morenews_preload_header_image()
{
// Check if there is a custom header image set for the theme.
if (has_header_image()) {
// Get the URL of the header image.
$morenews_background = get_header_image();
// Output the preload link for the header image.
echo '';
}
}
endif;
add_action('wp_head', 'morenews_preload_header_image');
function morenews_live_search_scripts()
{
// Check if AJAX search enabled
$enable_ajax = morenews_get_option('search_archive_enable_ajax');
$limit = absint(morenews_get_option('search_archive_ajax_results'));
if ($enable_ajax) {
wp_enqueue_script(
'morenews-live-search',
get_template_directory_uri() . '/assets/search-script.js',
array('jquery'),
null,
true
);
wp_localize_script('morenews-live-search', 'afLiveSearch', array(
'ajax_url' => admin_url('admin-ajax.php'),
'searching_text' => __('Searching...', 'morenews'),
'enabled' => (bool) $enable_ajax,
'results_count' => $limit > 0 ? $limit : 5,
'nonce' => wp_create_nonce('morenews_live_search'),
));
}
}
add_action('wp_enqueue_scripts', 'morenews_live_search_scripts');
function morenews_live_search_ajax()
{
// Security check
if (empty($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'morenews_live_search')) {
wp_send_json_error(['message' => __('Invalid security token.', 'morenews')]);
}
// Query text
$query = isset($_POST['s']) ? sanitize_text_field(wp_unslash($_POST['s'])) : '';
// Customizer controls
$search_archive_content_view = morenews_get_option('search_archive_content_view');
$limit = isset($_POST['limit']) ? absint($_POST['limit']) : absint(morenews_get_option('search_archive_ajax_results'));
if ($limit < 1) {
$limit = 5;
}
// Build query
$args = array(
's' => $query,
'posts_per_page' => $limit,
'post_status' => 'publish',
);
if ($search_archive_content_view !== 'all') {
$args['post_type'] = 'post';
}
$search = new WP_Query($args);
// Wrapper
echo '';
if ($search->have_posts()) {
echo '
';
while ($search->have_posts()) {
$search->the_post();
echo '- ';
do_action('morenews_action_loop_list', get_the_ID(), 'thumbnail', 0, false, false, false);
echo '
';
}
echo '
';
// View all link
echo '
';
} else {
echo '
';
echo esc_html__('No results found.', 'morenews');
echo '
';
}
echo '
';
wp_reset_postdata();
wp_die();
}
add_action('wp_ajax_morenews_live_search', 'morenews_live_search_ajax');
add_action('wp_ajax_nopriv_morenews_live_search', 'morenews_live_search_ajax');