/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } $query_args = array('post_type' => 'tb_book', 'posts_per_page' => 1, 'post__in' => array((int) $instance['book_id'])); $query = new WP_Query($query_args); //Return and spit an error if no book found. if (!$query->have_posts()) { echo '<p>' . __('The Selected Book Was Not Found', 'totally-booked') . '</p>'; return; } $query->the_post(); tb_get_template_part('book_widget'); wp_reset_query(); echo $after_widget; }
/** * Gets the buy now button, this is also where the HTML template for the popup is pulled in. * * @param int $post_id * @return string|void * @since 0.1 */ function tb_get_buynow_link($post_id = 0) { if ($post_id === 0) { $post_id = get_the_ID(); } //Need A Post ID. if (!$post_id) { return __('You must use The tb_get_buynow_link tag from within a WordPress loop or pass in the appropriate post ID.', 'totally-booked'); } $metas = $GLOBALS['TotallyBooked']->get_book_link_meta_details(); //Look First In The Cache $cache = wp_cache_get('popup_items_' . $post_id, 'totally-booked'); if ($cache && !empty($cache)) { $GLOBALS['popup_items'] = $cache; tb_get_template_part('buynow_popup'); return; } //Start with a blank array $popup_items = array(); foreach ($metas as $meta => $details) { $url = get_post_meta($post_id, $meta, true); if ($url && !empty($url)) { $popup_items[] = array('url' => $url, 'image' => $details['icon_url'], 'class' => $details['popup_class']); } } //If No Items, Return Nothing.. if (empty($popup_items)) { return ''; } //Set The Items To The Cache wp_cache_set('popup_items_' . $post_id, $popup_items, 'totally-booked'); $GLOBALS['popup_items'] = $popup_items; tb_get_template_part('buynow_popup'); }
* @since 0.1 */ get_header(); ?> <?php do_action('tb_wrapper_start'); ?> <header class="archive-header"> <h1 class="archive-title"><?php tb_archive_title(); ?> </h1> </header><!-- .archive-header --> <?php if (have_posts()) { while (have_posts()) { the_post(); tb_get_template_part('loops/archive'); } } ?> <?php do_action('tb_wrapper_end'); ?> <?php get_footer();
/** * The shortcode to display a single series gallery * * [tb_series_gallery slug="some-slug"] * * @param $atts * @return string * @since 0.1 */ function series_gallery_shortcode($atts) { extract(shortcode_atts(array('slug' => false, 'columns' => 3), $atts)); if (!$slug) { return ''; } $query_args = array('post_type' => 'tb_book', 'posts_per_page' => -1, 'post_status' => 'publish', 'tax_query' => array(array('taxonomy' => 'tb_series', 'field' => 'slug', 'terms' => esc_attr($slug)))); $query = new WP_Query($query_args); $out = ''; ob_start(); $i = 1; echo '<div class="tb_gallery_wrapper">'; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); tb_get_template_part(apply_filters('tb_series_shortcode_template_part', 'loops/gallery')); if ($i % (int) $columns === 0) { echo '<div class="clear"></div>'; } $i++; } } echo '<div class="clear"></div>'; echo '</div>'; $out .= ob_get_contents(); ob_end_clean(); return $out; }
<?php /** * Single Book Template For The Totally Booked Plugin * * @version 0.1 * @package totally-booked */ get_header(); ?> <?php do_action('tb_wrapper_start'); ?> <?php the_post(); ?> <?php tb_get_template_part('loops/single_book'); ?> <?php do_action('tb_wrapper_end'); ?> <?php get_footer();
/** * Output the HTML in the options page if any entered instead of looking for a template file. * * @since 0.2 */ public function wrapper_end() { $wrapper_end = get_option('tb_wrapper_end'); if ($wrapper_end && !empty($wrapper_end)) { echo $wrapper_end; } else { tb_get_template_part('parts/wrapper_end'); } }