function alaya_post_list($number = 5, $thumbnail = 'yes', $category_slug = '') { global $post; $tmp_post = $post; if ($category_slug != '') { $category_array = explode(',', $category_slug); $args = array('numberposts' => $number, 'orderby' => 'post_date', 'order' => 'DESC', 'tax_query' => array(array('taxonomy' => 'category', 'field' => 'slug', 'terms' => $category_array, 'include_children' => false))); } else { $args = array('numberposts' => $number, 'orderby' => 'post_date', 'order' => 'DESC'); } $posts = get_posts($args); $date = ''; $post_list = ''; $post_list .= '<ul class="post_list">'; foreach ($posts as $post) { setup_postdata($post); $url = get_permalink($post->ID); $title = $post->post_title; $post_list .= '<li class="post-list-' . $post->ID . '">'; if ($thumbnail == 'yes') { if (has_post_thumbnail($post->ID)) { $image_id = get_post_thumbnail_id($post->ID); $thumbnail_url = wp_get_attachment_image_src($image_id, 'thumbnail', true); $post_list .= '<a href="' . esc_url($url) . '" class="thumbnail"><img src="' . esc_url($thumbnail_url[0]) . '" alt="' . esc_attr($title) . '" /></a>'; } $date = '<p>' . get_the_time(get_option('date_format')) . '</p>'; } $post_list .= '<a href="' . esc_url($url) . '" class="post_title">' . esc_attr(alaya_truncate($title, 45)) . '</a>'; $post_list .= $date; $post_list .= '<div class="clear"></div></li>'; } $post_list .= '</ul>'; $post = $tmp_post; return $post_list; }
function alaya_scrolling_posts($title = 'The Latest Posts', $columns = 3, $header = "horizontal", $number = 6, $category_slug = '', $only_sticky) { global $post, $more; $tmp_post = $post; $tmp_more = $more; $args = array('numberposts' => $number, 'orderby' => 'post_date', 'order' => 'DESC'); if ($category_slug != '') { $category_array = explode(',', $category_slug); $args = array('numberposts' => $number, 'orderby' => 'post_date', 'order' => 'DESC', 'tax_query' => array(array('taxonomy' => 'category', 'field' => 'slug', 'terms' => $category_array, 'include_children' => false))); } if ($only_sticky == 'yes') { $sticky = get_option('sticky_posts'); $args['post__in'] = $sticky; $args['ignore_sticky_posts'] = false; } $posts = get_posts($args); $i = 0; $section_id = 'scrolling_posts_' . alaya_random_string(6, false); $post_slide = '<section id="' . $section_id . '" class="scrolling_posts flexslider">' . PHP_EOL; $post_slide .= '<header class="' . $header . '"> <h5 class="archive_title"><span>' . esc_attr($title) . '</span></h5>' . PHP_EOL; if ($number > 3 && count($posts) > 3) { $post_slide .= '<div class="controlNav"><a href="javascript:void(0);" id="prev_' . $section_id . '" class="prev"><i class="fa fa-chevron-left"></i></a> <a href="javascript:void(0);" class="next" id="next_' . $section_id . '"><i class="fa fa-chevron-right"></i></a></div>'; } $post_slide .= '</header>' . PHP_EOL; $post_slide .= '<ul class="slides columns' . $columns . '">' . PHP_EOL; if ($i != count($posts)) { $post_slide .= '<li>' . PHP_EOL; } foreach ($posts as $post) { setup_postdata($post); $image_id = get_post_thumbnail_id($post->ID); $thumbnail_url = wp_get_attachment_image_src($image_id, 'blog_thumbnail', true); $more = 0; $url = get_permalink($post->ID); $title = $post->post_title; $post_slide .= '<div class="blog-post post">'; if (has_post_thumbnail()) { $post_slide .= '<div class="thumbnail"><a href="' . $url . '" title="' . $title . '"><img src="' . $thumbnail_url[0] . '" class="featured_image" alt="' . $title . '" /></a></div>'; } $post_slide .= '<span>' . get_the_category_list(', ') . '</span>'; $post_slide .= '<h4><a href="' . $url . '" title="' . $title . '">' . $title . '</a></h4>'; $post_slide .= '<p>' . alaya_truncate(get_the_excerpt(), 150) . '</p>'; $post_slide .= '</div>' . PHP_EOL; $i++; if ($i % $columns == 0) { $post_slide .= '</li>' . PHP_EOL; if ($i != count($posts)) { $post_slide .= '<li>' . PHP_EOL; } } } $post_slide .= '</ul><div class="clearfix"></div>'; $post_slide .= '<div class="' . $section_id . '_alaya_loader alaya_loader" style="top:50%;left:47%;"><i class="fa fa-spinner fa-spin"></i></div>' . PHP_EOL; $post_slide .= '</section>'; $post_slide .= "<script type='text/javascript'>\r\n\t\tjQuery(document).ready(function(\$){\r\n\t\t\t/*Scrolling Posts*/\r\n\t\t\t\$(window).load(function(){\r\n\t\t\t\t\$('#" . $section_id . "').flexslider({\r\n\t\t\t\t slideshow:true,\r\n\t\t\t\t video: true,\r\n\t\t\t\t keyboard: true,\r\n\t\t\t\t animation: 'slide',\r\n\t\t\t\t directionNav: false, \r\n\t\t\t\t controlNav:false,\r\n\t\t\t\t smoothHeight:false,\r\n\t\t\t\t mousewheel: false, \r\n\t\t\t\t multipleKeyboard: true, \r\n\t\t\t\t animationLoop: false, \r\n\t\t\t\t pauseOnHover:true,\r\n\t\t\t\t slideshowSpeed: 20000,\r\n\t\t\t\t prevText:'',\r\n\t\t\t\t nextText:'',\r\n\t\t\t\t start:function(){\r\n\t\t\t\t\t \$('." . $section_id . "_alaya_loader').hide();\r\n\t\t\t\t\t \$('#" . $section_id . " .thumbnail').each(function(){\r\n\t\t\t\t\t\t var overlay_width,overlay_height,marginTop,marginLeft;\r\n\t\t\t\t\t var wrapper_width=\$(this).width();var wrapper_height=\$(this).height(); \r\n\t\t\t\t\t\t if(\$(this).children('img').height()<wrapper_height){\r\n\t\t\t\t\t\t \$(window).load(function(){\r\n\t\t\t\t\t\t\twrapper_height=\$(this).children('img').height();\r\n\t\t\t\t\t\t if(wrapper_height==0){\r\n\t\t\t\t\t\t\t wrapper_height=200;\r\n\t\t\t\t\t\t }\r\n\t\t\t\t\t\t\t\$(this).css('height',wrapper_height);\r\n\t\t\t\t\t\t })\t\t\t\t\t \r\n\t\t\t\t\t\t }\t \r\n\t\t\t\t\t\t if(\$(window).width()>800){\r\n\t\t\t\t\t overlay_width=wrapper_width-20;\r\n\t\t\t\t\t\t overlay_height=wrapper_height-20;\r\n\t\t\t\t\t\t }else{\r\n\t\t\t\t\t\t overlay_width=wrapper_width;\r\n\t\t\t\t\t\t overlay_height=wrapper_height;\r\n\t\t\t\t\t\t }\r\n\t\t\t\t\t\t marginTop=overlay_height/2;\r\n\t\t\t\t\t\t marginLeft=overlay_width/2;\r\n\t\t\t\t\t \$(this).children('.overlay').css({\r\n\t\t\t\t\t\t width:overlay_width+'px',\r\n\t\t\t\t\t\t height:overlay_height+'px',\r\n\t\t\t\t\t\t marginTop:'-'+marginTop+'px',\r\n\t\t\t\t\t\t marginLeft:'-'+marginLeft+'px'\r\n\t\t\t\t\t });\r\n\t\t\t\t\t\t \$(this).children('.overlay').children('i').css({\r\n\t\t\t\t\t\t width:'20px',\r\n\t\t\t\t\t\t height:'20px',\r\n\t\t\t\t\t\t display:'block',\r\n\t\t\t\t\t\t left:'50%',\r\n\t\t\t\t\t\t top:'50%',\r\n\t\t\t\t\t\t position:'absolute',\r\n\t\t\t\t\t\t marginTop:'-10px',\r\n\t\t\t\t\t\t marginLeft:'-10px'\r\n\t\t\t\t\t });\r\n\t\t\t\t\t });\r\n\t\t\t\t }\r\n\t\t\t });\r\n\t\t\t });\r\n\t\t\t \$('#prev_" . $section_id . ", #next_" . $section_id . "').on('click', function(){\r\n\t\t\t var action = \$(this).attr('class');\r\n\t\t\t \$('#" . $section_id . "').flexslider(action);\r\n\t\t\t return false;\r\n\t\t });\r\n\t });\r\n\t </script>"; $post = $tmp_post; $more = $tmp_more; return $post_slide; }
function alaya_post_loop($atts) { static $alaya_custom_loop; if (!isset($alaya_custom_loop)) { $alaya_custom_loop = 1; } else { $alaya_custom_loop++; } $sticky = get_option('sticky_posts'); $atts = shortcode_atts(array('paging' => 'paginate' . $alaya_custom_loop, 'post_type' => 'post', 'posts_per_page' => '10', 'post_status' => 'publish', 'category_name' => '', 'columns' => 3, 'template' => 'standard', 'hide_sticky_posts' => 'no', 'pagination' => 'no', 'orderby' => 'date'), $atts); $paging = $atts['paging']; unset($atts['paging']); $hide_sticky_posts = $atts['hide_sticky_posts']; unset($atts['hide_sticky_posts']); $pagination = $atts['pagination']; unset($atts['pagination']); $template = $atts['template']; unset($atts['template']); $columns = $atts['columns']; unset($atts['columns']); if (isset($_GET[$paging])) { $atts['paged'] = $_GET[$paging]; } else { $atts['paged'] = 1; } if ($hide_sticky_posts == 'yes') { $atts['post__not_in'] = $sticky; $atts['ignore_sticky_posts'] = 1; } else { $atts['ignore_sticky_posts'] = false; } $custom_query = new WP_Query($atts); $pagination_base = add_query_arg($paging, '%#%'); $wrapper = ""; $post_class_ex = ""; if ($template == 'standard' || $template == 'list') { $wrapper = '<div class="standard_blog">'; } elseif ($template == 'masonry') { if ($columns == 3) { $wrapper = '<div class="masonry_blog">'; $post_class_ex = ' three_columns'; } elseif ($columns == 2) { $wrapper = '<div class="masonry_blog_2">'; $post_class_ex = ' two_columns'; } } if ($custom_query->have_posts()) { $html = $wrapper; while ($custom_query->have_posts()) { $custom_query->the_post(); $thumbnail = ''; $excerpt = get_the_excerpt(); $more = '<a class="morelink" href="' . esc_url(get_permalink()) . '">' . __('Continue to read', 'alaya') . ' <i class="fa fa-long-arrow-right"></i></a>'; $post_icon = '<a class="overlay" href="' . esc_url(get_permalink()) . '">' . alaya_format_icon() . '</a>'; if (has_post_format() == 0) { $post_icon = ''; } if (has_post_thumbnail()) { $thumbnail = '<div class="thumbnail">' . $post_icon . ' <a href="' . esc_url(get_permalink()) . '">' . get_the_post_thumbnail(get_the_ID(), 'large') . '</a></div>'; } else { $thumbnail = '<div class="post_format_icon">' . alaya_format_icon() . '</div>'; } if ($template == 'list') { $post_class_ex = ' thumbnail_s'; $excerpt = alaya_truncate(get_the_excerpt(), 150); } $html .= sprintf('<article class="post' . esc_attr($post_class_ex) . '"> %4$s <div class="entry-body"> <span class="category">%5$s</span> <h4 class="entry-title"><a href="%1$s" title="%2$s">%2$s</a></h4> <span class="title-divider"></span> <div class="entry-content">%3$s</div> <footer class="entry-tools"> <span>%7$s</span> %6$s </footer> </div> <div class="clear"></div> </article>', get_permalink(), get_the_title(), $excerpt, $thumbnail, get_the_category_list(', '), $more, get_the_time(get_option('date_format'))); } $html .= '</div>'; if ($pagination == 'yes') { $html .= '<div class="alaya_pagenavi">'; $html .= paginate_links(array('type' => '', 'base' => $pagination_base, 'format' => '?' . $paging . '=%#%', 'current' => max(1, $custom_query->get('paged')), 'total' => $custom_query->max_num_pages)); $html .= '</div>'; } } return $html; }