Esempio n. 1
0
function fastfood_single_nav()
{
    global $post;
    if (!is_single()) {
        return;
    }
    $next = get_next_post();
    $prev = get_previous_post();
    $next_title = get_the_title($next) ? get_the_title($next) : __('Next Post', 'fastfood');
    $prev_title = get_the_title($prev) ? get_the_title($prev) : __('Previous Post', 'fastfood');
    $output = '';
    if ($prev) {
        $output .= fastfood_build_link(array('href' => get_permalink($prev), 'text' => '<span>' . $prev_title . '</span>' . fastfood_get_the_thumb(array('id' => $prev->ID, 'size' => array(32, 32), 'class' => 'tb-thumb-format')), 'title' => esc_attr(strip_tags(__('Previous Post', 'fastfood') . ': ' . $prev_title)), 'class' => 'nav-previous el-icon-chevron-left', 'rel' => 'prev'));
    }
    if ($next) {
        $output .= fastfood_build_link(array('href' => get_permalink($next), 'text' => '<span>' . $next_title . '</span>' . fastfood_get_the_thumb(array('id' => $next->ID, 'size' => array(32, 32), 'class' => 'tb-thumb-format')), 'title' => esc_attr(strip_tags(__('Next Post', 'fastfood') . ': ' . $next_title)), 'class' => 'nav-next el-icon-chevron-right', 'rel' => 'next'));
    }
    if (!$output) {
        return;
    }
    ?>

		<div class="nav-single">
			<?php 
    echo $output;
    ?>
		</div><!-- #nav-single -->

	<?php 
}
Esempio n. 2
0
    function widget($args, $instance)
    {
        $cache = wp_cache_get('tb_recent_posts', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        $instance = $this->validate_and_sanitize($instance);
        extract($args);
        extract($instance);
        if ($category === -1) {
            if (!is_single() || is_attachment()) {
                return;
            }
            global $post;
            $category = get_the_category($post->ID);
            $category = $category ? $category[0]->cat_ID : '';
        }
        $title = apply_filters('widget_title', $title, $instance, $this->id_base);
        $title = sprintf($title, '<a href="' . get_category_link($category) . '">' . get_cat_name($category) . '</a>');
        $r = new WP_Query(array('cat' => $category, 'posts_per_page' => $number, 'no_found_rows' => true, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
        if ($r->have_posts()) {
            ?>

		<?php 
            echo $before_widget;
            ?>
		<?php 
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            ?>
		<?php 
            if ($description && category_description($category)) {
                echo '<div class="description">' . category_description($category) . '</div>';
            }
            ?>
		<ul>
		<?php 
            while ($r->have_posts()) {
                $r->the_post();
                $the_id = get_the_ID();
                $the_title = get_the_title() ? get_the_title() : $the_id;
                $the_class = $thumb ? ' class="li-with-thumbs"' : '';
                $the_format = get_post_format() ? get_post_format() : 'standard';
                $the_thumb = $thumb ? fastfood_get_the_thumb(array('id' => $the_id, 'size' => array(32, 32), 'default' => '<span class="tbm-format f-' . $the_format . '"></span>')) : '';
                echo sprintf('<li%1$s><a href="%2$s" title="%3$s">%4$s%5$s</a></li>', $the_class, esc_url(get_permalink()), esc_attr($the_title), $the_thumb, esc_html($the_title)) . "\n";
            }
            ?>
		</ul>
		<?php 
            echo $after_widget;
            ?>

<?php 
            // Reset the global $the_post as this query will have stomped on it
            wp_reset_postdata();
        }
        $cache[$args['widget_id']] = ob_get_flush();
        wp_cache_set('tb_recent_posts', $cache, 'widget');
    }