'post',
'posts_per_page' => $vmagazine_ticker_count,
'cat' => absint($vmagazine_ticker_cat),
'ignore_sticky_posts' => 1
);
}else{
$vmagazine_ticker_args = array(
'post_type' => 'post',
'posts_per_page' => $vmagazine_ticker_count,
'ignore_sticky_posts' => 1
);
}
$vmagazine_ticker_query = new WP_Query( $vmagazine_ticker_args );
if( $vmagazine_ticker_query->have_posts() ) { ?>
';
while( $vmagazine_ticker_query->have_posts() ) {
$vmagazine_ticker_query->the_post();
?>
'; ?>
';
echo '
';
}
endif;
/**
* Menu fallback
*/
function vmagazine_lite_wp_page_menu() {
wp_page_menu();
}
/*===========================================================================================================*/
/**
* Get media attachment id from url
*/
if ( ! function_exists( 'vmagazine_lite_get_attachment_id_from_url' ) ):
function vmagazine_lite_get_attachment_id_from_url( $attachment_url ) {
global $wpdb;
$attachment_id = false;
// If there is no url, return.
if ( '' == $attachment_url )
return;
// Get the upload directory paths
$upload_dir_paths = wp_upload_dir();
// Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
if ( false !== strpos( $attachment_url, $upload_dir_paths['baseurl'] ) ) {
// If this is the URL of an auto-generated thumbnail, get the URL of the original image
$attachment_url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url );
// Remove the upload path base directory from the attachment URL
$attachment_url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $attachment_url );
// Finally, run a custom database query to get the attachment ID from the modified attachment URL
$attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $attachment_url ) );
}
return $attachment_id;
}
endif;
/*===========================================================================================================*/
/**
* Function define about page/post/archive sidebar
*/
if( ! function_exists( 'vmagazine_lite_get_sidebar' ) ):
function vmagazine_lite_get_sidebar() {
global $post;
if( $post ) {
$sidebar_meta_option = 'default_sidebar';
}
if( is_home() ) {
$set_id = get_option( 'page_for_posts' );
$sidebar_meta_option = 'default_sidebar';
}
if( empty( $sidebar_meta_option ) || is_archive() || is_search() ) {
$sidebar_meta_option = 'default_sidebar';
}
$vmagazine_archive_sidebar = get_theme_mod( 'vmagazine_archive_sidebar', 'right_sidebar' );
$vmagazine_post_default_sidebar = get_theme_mod( 'vmagazine_default_post_sidebar', 'right_sidebar' );
$vmagazine_page_default_sidebar = get_theme_mod( 'vmagazine_default_page_sidebar', 'right_sidebar' );
if( $sidebar_meta_option == 'default_sidebar' ) {
if( is_single() ) {
if( $vmagazine_post_default_sidebar == 'right_sidebar' ) {
get_sidebar();
} elseif( $vmagazine_post_default_sidebar == 'left_sidebar' ) {
get_sidebar( 'left' );
} elseif( $vmagazine_post_default_sidebar == 'both_sidebar' ) {
get_sidebar();
get_sidebar( 'left' );
}
} elseif( is_page() ) {
if( $vmagazine_page_default_sidebar == 'right_sidebar' ) {
get_sidebar();
} elseif( $vmagazine_page_default_sidebar == 'left_sidebar' ) {
get_sidebar( 'left' );
} elseif( $vmagazine_page_default_sidebar == 'both_sidebar' ) {
get_sidebar();
get_sidebar( 'left' );
}
} elseif( $vmagazine_archive_sidebar == 'right_sidebar' ) {
get_sidebar();
} elseif( $vmagazine_archive_sidebar == 'left_sidebar' ) {
get_sidebar( 'left' );
} elseif( $vmagazine_archive_sidebar == 'both_sidebar' ) {
get_sidebar();
get_sidebar( 'left' );
}
} elseif( $sidebar_meta_option == 'right_sidebar' ) {
get_sidebar();
} elseif( $sidebar_meta_option == 'left_sidebar' ) {
get_sidebar( 'left' );
} elseif( $sidebar_meta_option == 'both_sidebar' ) {
get_sidebar();
get_sidebar( 'left' );
}
}
endif;
/*===========================================================================================================*/
/**
* Function for excerpt length
*/
if( ! function_exists( 'vmagazine_lite_get_excerpt_content' ) ):
function vmagazine_lite_get_excerpt_content( $limit ) {
$striped_contents = strip_shortcodes( get_the_content() );
$striped_content = strip_tags( $striped_contents );
$limit_content = substr( $striped_content, 0 , $limit );
return $limit_content;
}
endif;
/*===========================================================================================================*/
/**
* Post title excerpt
*/
if( ! function_exists( 'vmagazine_lite_title_excerpt' ) ):
function vmagazine_lite_title_excerpt( $limit ) {
$title = get_the_title();
$limit_content = substr( $title, 0 , $limit );
$title_length = strlen($title);
if( $title_length > $limit){
$limit_content .= '...';
}
return $limit_content;
}
endif;
/*===========================================================================================================*/
// Remove issues with pref-etching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
/*===========================================================================================================*/
/**
* Fallback image for widgets
*
*/
if( !function_exists( 'vmagazine_lite_home_element_img' ) ) :
function vmagazine_lite_home_element_img($img_size='full') {
$fallback_option = get_theme_mod( 'post_fallback_img_option', 'show' );
$fallback_img_url = get_theme_mod( 'post_fallback_image' );
$img_src = '';
if( has_post_thumbnail() ) {
$image_id = get_post_thumbnail_id();
$image_path = wp_get_attachment_image_src( $image_id, $img_size, true );
$img_src = $image_path[0];
} elseif( $fallback_option == 'show' && !empty( $fallback_img_url ) ) {
$fallback_img_id = vmagazine_lite_get_attachment_id_from_url( $fallback_img_url );
$fallback_image_url = wp_get_attachment_image_src( $fallback_img_id, $img_size, true );
$img_src = $fallback_image_url[0];
}
return $img_src;
}
endif;
/*===========================================================================================================*/
/***
* load images on frontend
*/
if( ! function_exists('vmagazine_lite_load_images') ){
function vmagazine_lite_load_images($img_src){
$vmagazine_lazyload_option = get_theme_mod('vmagazine_lazyload_option','enable');
if( $vmagazine_lazyload_option == 'enable' ){ ?>
; ?>)
ID;
$fallback_option = get_theme_mod( 'post_fallback_img_option', 'show' );
$fallback_img_url = get_theme_mod( 'post_fallback_image' );
if( has_post_thumbnail() ) {
echo '
';
the_post_thumbnail( 'vmagazine-single-large' );
echo '
';
} elseif( $fallback_option == 'show' && !empty( $fallback_img_url ) ) {
$fallback_img_id = vmagazine_lite_get_attachment_id_from_url( $fallback_img_url );
$fallback_image_url = wp_get_attachment_image_src( $fallback_img_id, 'vmagazine-single-large', true );
echo '
';
}
}
endif;
/*===========================================================================================================*/
/**
* Change layout for comment
*/
function vmagazine_lite_comment_list( $comment, $args, $depth ) {
?>
id="li-comment-">
%1$s%2$s%3$s ';
$date = sprintf( $date,
get_the_date('j'),
get_the_date('M'),
get_the_date('Y')
);
$posted_on = $date;
echo '