function widget($args, $instance) { /*Backup query string for later use*/ global $query_string; $backup_query_string = $query_string; extract($args); $title = apply_filters('widget_title', $instance['title']); if (empty($title)) { $title = false; } $related_type = $instance['related_type']; $description = $instance['description']; $thumbnail = $instance['thumbnail'] == 1 ? true : false; $posttitle = $instance['posttitle'] == 1 ? true : false; $byline = $instance['byline'] == 1 ? true : false; $excerpt = $instance['excerpt'] == 1 ? true : false; $meta = $instance['meta'] == 1 ? true : false; $number = intval($instance['number']); global $wp_query; global $post; $curr_id = $post->ID; if (!is_single()) { return; } echo $before_widget; if ($title) { echo $before_title; echo $title; echo $after_title; } if ($description != "") { echo '<p>' . stripslashes($description) . '</p>'; } $count = 0; if ($related_type == "category") { $categories = get_the_category(); $catlist = array(); foreach ($categories as $category) { $catlist[] = $category->cat_ID; } $args = array('posts_per_page' => $number, 'category__in' => $catlist, 'post__not_in' => array($curr_id)); $related_query = new WP_Query($args); if ($related_query->have_posts()) { echo '<ul>'; while ($related_query->have_posts()) { $related_query->the_post(); ?> <li class="cf"> <?php if ($thumbnail) { ?> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php dt_image(60, 60); ?> </a> <?php } ?> <?php if ($posttitle) { ?> <h2><a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php the_title(); ?> </a></h2> <?php } ?> <?php if ($byline) { ?> <!--BEGIN .post-meta .post-header--> <div class="post-meta post-header"> <span class="meta-author"><?php _e('Posted by', 'engine'); ?> <?php the_author_posts_link(); ?> </span> <span class="meta-published"><?php _e('on', 'engine'); ?> <?php the_time(get_option('date_format')); ?> </span> <!--END .post-meta post-header --> </div> <?php } ?> <?php if ($excerpt) { ?> <?php dt_excerpt(25); ?> <?php } ?> <?php if ($meta) { ?> <!--BEGIN .post-meta .post-footer--> <div class="post-meta post-footer"> <span class="meta-categories"><?php _e('Posted in', 'engine'); ?> <?php the_category(', '); ?> </span> <span class="meta-comment"><?php comments_popup_link(__('No Comments', 'engine'), __('1 Comment', 'engine'), __('% Comments', 'engine')); ?> </span> <!--END .post-meta .post-footer--> </div> <?php } ?> </li> <?php } echo '</ul>'; } ##END CATEGORIES## } elseif ($related_type == "tags") { $tags = get_the_tags(); if (!$tags) { echo '<p>No related posts</p>'; echo $after_widget; return; } $taglist = array(); foreach ($tags as $tag) { $taglist[] = $tag->term_id; } $args = array('posts_per_page' => $number, 'tag__in' => $taglist, 'post__not_in' => array($curr_id)); $related_query = new WP_Query($args); if ($related_query->have_posts()) { echo '<ul>'; while ($related_query->have_posts()) { $related_query->the_post(); ?> <li class="cf"> <?php if ($thumbnail) { ?> <?php dt_image(60, 60); ?> <?php } ?> <?php if ($posttitle) { ?> <h2><a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php the_title(); ?> </a></h2> <?php } ?> <?php if ($byline) { ?> <!--BEGIN .post-meta .post-header--> <div class="post-meta post-header"> <span class="meta-author"><?php _e('Posted by', 'engine'); ?> <?php the_author_posts_link(); ?> </span> <span class="meta-published"><?php _e('on', 'engine'); ?> <?php the_time(get_option('date_format')); ?> </span> <!--END .post-meta post-header --> </div> <?php } ?> <?php if ($excerpt) { ?> <?php dt_excerpt('25'); ?> <?php } ?> <?php if ($meta) { ?> <!--BEGIN .post-meta .post-footer--> <div class="post-meta post-footer"> <span class="meta-categories"><?php _e('Posted in', 'engine'); ?> <?php the_category(', '); ?> </span> <span class="meta-comment"><?php comments_popup_link(__('No Comments', 'engine'), __('1 Comment', 'engine'), __('% Comments', 'engine')); ?> </span> <!--END .post-meta .post-footer--> </div> <?php } ?> </li> <?php } echo '</ul>'; } ##END TAGS## } else { $the_author = $wp_query->post->post_author; $args = array('posts_per_page' => $number, 'author' => $the_author, 'post__not_in' => array($curr_id)); $related_query = new WP_Query($args); if ($related_query->have_posts()) { echo '<ul>'; while ($related_query->have_posts()) { $related_query->the_post(); ?> <li class="cf"> <?php if ($thumbnail) { ?> <?php dt_image(60, 60); ?> <?php } ?> <?php if ($posttitle) { ?> <h2><a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php the_title(); ?> </a></h2> <?php } ?> <?php if ($byline) { ?> <!--BEGIN .post-meta .post-header--> <div class="post-meta post-header"> <span class="meta-author"><?php _e('Posted by', 'engine'); ?> <?php the_author_posts_link(); ?> </span> <span class="meta-published"><?php _e('on', 'engine'); ?> <?php the_time(get_option('date_format')); ?> </span> <!--END .post-meta post-header --> </div> <?php } ?> <?php if ($excerpt) { ?> <?php dt_excerpt('25'); ?> <?php } ?> <?php if ($meta) { ?> <!--BEGIN .post-meta .post-footer--> <div class="post-meta post-footer"> <span class="meta-categories"><?php _e('Posted in', 'engine'); ?> <?php the_category(', '); ?> </span> <span class="meta-comment"><?php comments_popup_link(__('No Comments', 'engine'), __('1 Comment', 'engine'), __('% Comments', 'engine')); ?> </span> <!--END .post-meta .post-footer--> </div> <?php } ?> </li> <?php } echo '</ul>'; } } ##END AUTHOR## echo $after_widget; /*Reset query to initial*/ query_posts($backup_query_string); the_post(); }
the_category(', '); ?> </span> <h2 class="post-title"><a href="<?php the_permalink(); ?> "><?php the_title(); ?> <span class="plus"><span>+</span> </span></a></h2> <!--BEGIN .post-content --> <div class="post-content"> <?php dt_excerpt(20); ?> <!--END .post-content --> </div> <a class="read-more" href="<?php the_permalink(); ?> "><?php _e('Read More', 'engine'); ?> <span class="plus"><span>+</span> </span></a> <span class="meta-published"><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ' . __('ago', 'engine'); ?>
<?php if (!post_password_required() && (comments_open() || get_comments_number())) { ?> <span class="comments-link"><i class="fa fa-comment-o"></i><?php comments_popup_link(esc_html__('Leave a comment', 'ticketbox'), esc_html__('1 Comment', 'ticketbox'), esc_html__('% Comments', 'ticketbox')); ?> </span> <?php } ?> </div><!-- .entry-meta --> </header><!-- .entry-header --> <?php if (has_excerpt()) { dt_excerpt(); } else { ?> <div class="entry-content"> <?php /* translators: %s: Name of current post */ the_content(sprintf(__('Continue reading<span class="screen-reader-text"> "%s"</span>', 'ticketbox'), get_the_title())); wp_link_pages(array('before' => '<div class="page-links"><span class="page-links-title">' . __('Pages:', 'ticketbox') . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>', 'pagelink' => '<span class="screen-reader-text">' . __('Page', 'ticketbox') . ' </span>%', 'separator' => '<span class="screen-reader-text">, </span>')); ?> <?php edit_post_link(esc_html__('Edit', 'ticketbox'), '<div class="edit-link">', '</div>'); ?> </div> <?php }
function widget($args, $instance) { /*Backup query string for later use*/ global $query_string; $backup_query_string = $query_string; extract($args); $title = apply_filters('widget_title', $instance['title']); if (empty($title)) { $title = false; } $posttype = $instance['posttype']; $sort_by = $instance['sort_by']; $description = $instance['description']; $thumbnail = $instance['thumbnail'] == 1 ? true : false; $posttitle = $instance['posttitle'] == 1 ? true : false; $byline = $instance['byline'] == 1 ? true : false; $excerpt = $instance['excerpt'] == 1 ? true : false; $meta = $instance['meta'] == 1 ? true : false; //Check if displaying only thumbs if ($thumbnail == true && $posttitle == false && $byline == false && $excerpt == false && $meta == false) { $onlythumbs = 'onlythumbs'; } $number = absint($instance['number']); $categories = (array) $instance['categories']; $tags = (array) $instance['tags']; $author = intval($instance['author']); echo $before_widget; if ($title) { echo $before_title; echo $title; echo $after_title; } if ($description != "") { echo '<p class="description">' . stripslashes($description) . '</p>'; } $args = array(); //Number $args['posts_per_page'] = $number; //Post type if ($posttype == "categories") { $args['category__in'] = $categories; } elseif ($posttype == "tags") { $args['tag__in'] = $tags; } elseif ($posttype == "author") { $args['author'] = $author; } //Order by if ($sort_by == "popular") { $args['orderby'] = "comment_count"; } elseif ($sort_by == "random") { $args['orderby'] = "rand"; } else { $args['orderby'] = "date"; } $get_posts_query = new WP_Query($args); if ($get_posts_query->have_posts()) { echo '<ul class="cf">'; while ($get_posts_query->have_posts()) { $get_posts_query->the_post(); ################################ # DISPLAY POST CONTENT START # ################################ ?> <li class="cf"> <?php if ($thumbnail) { ?> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php dt_image(60, 60); ?> </a> <?php } ?> <?php if ($posttitle) { ?> <h2 class="post-title"><a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php the_title(); ?> </a></h2> <?php } ?> <?php if ($byline) { ?> <!--BEGIN .post-meta .post-header--> <div class="post-meta post-header"> <span class="meta-author"><?php _e('Posted by', 'engine'); ?> <?php the_author_posts_link(); ?> </span> <span class="meta-published"><?php _e('on', 'engine'); ?> <?php the_time(get_option('date_format')); ?> </span> <!--END .post-meta post-header --> </div> <?php } ?> <?php if ($excerpt) { ?> <?php dt_excerpt(25); ?> <?php } ?> <?php if ($meta) { ?> <!--BEGIN .post-meta .post-footer--> <div class="post-meta post-footer"> <span class="meta-categories"><?php _e('Posted in', 'engine'); ?> <?php the_category(', '); ?> </span> <span class="meta-comment"><?php comments_popup_link(__('No Comments', 'engine'), __('1 Comment', 'engine'), __('% Comments', 'engine')); ?> </span> <!--END .post-meta .post-footer--> </div> <?php } ?> </li> <?php ############################### # DISPLAY POST CONTENT END # ############################### } echo '</ul>'; } echo $after_widget; /*Reset query to initial*/ query_posts($backup_query_string); the_post(); }