Ejemplo n.º 1
0
/**
 * Return the first link from the post content. If none found, the
 * post permalink is used as a fallback.
 *
 * @since Twenty Eleven 1.0
 *
 * @uses get_url_in_content() to get the first URL from the post content.
 *
 * @return string The first link.
 */
function twentyeleven_get_first_url()
{
    $content = get_the_content();
    $has_url = function_exists('get_url_in_content') ? get_url_in_content($content) : false;
    if (!$has_url) {
        $has_url = twentyeleven_url_grabber();
    }
    /** This filter is documented in wp-includes/link-template.php */
    return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}
Ejemplo n.º 2
0
/**
 * Return the first link from the post content. If none found, the
 * post permalink is used as a fallback.
 *
 * @return string
 */
function twentyeleven_get_first_url()
{
    $has_url = function_exists('get_the_post_format_url') ? get_the_post_format_url() : false;
    if (!$has_url) {
        $has_url = twentyeleven_url_grabber();
    }
    return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}
Ejemplo n.º 3
0
    /**
     * Outputs the HTML for this widget.
     *
     * @param array An array of standard parameters for widgets in this theme
     * @param array An array of settings for this widget instance
     * @return void Echoes it's output
     **/
    function widget($args, $instance)
    {
        $cache = wp_cache_get('widget_twentyeleven_ephemera', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (!isset($args['widget_id'])) {
            $args['widget_id'] = null;
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        extract($args, EXTR_SKIP);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Ephemera', 'twentyeleven') : $instance['title'], $instance, $this->id_base);
        if (!isset($instance['number'])) {
            $instance['number'] = '10';
        }
        if (!($number = absint($instance['number']))) {
            $number = 10;
        }
        $ephemera_args = array('order' => 'DESC', 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'post__not_in' => get_option('sticky_posts'), 'tax_query' => array(array('taxonomy' => 'post_format', 'terms' => array('post-format-aside', 'post-format-link', 'post-format-status', 'post-format-quote'), 'field' => 'slug', 'operator' => 'IN')));
        $ephemera = new WP_Query($ephemera_args);
        if ($ephemera->have_posts()) {
            echo $before_widget;
            echo $before_title;
            echo $title;
            // Can set this with a widget option, or omit altogether
            echo $after_title;
            ?>
			<ol>
			<?php 
            while ($ephemera->have_posts()) {
                $ephemera->the_post();
                ?>

				<?php 
                if ('link' != get_post_format()) {
                    ?>

				<li class="widget-entry-title">
					<a href="<?php 
                    echo esc_url(get_permalink());
                    ?>
" title="<?php 
                    printf(esc_attr__('Permalink to %s', 'twentyeleven'), the_title_attribute('echo=0'));
                    ?>
" rel="bookmark"><?php 
                    the_title();
                    ?>
</a>
					<span class="comments-link">
						<?php 
                    comments_popup_link(__('0 <span class="reply">comments &rarr;</span>', 'twentyeleven'), __('1 <span class="reply">comment &rarr;</span>', 'twentyeleven'), __('% <span class="reply">comments &rarr;</span>', 'twentyeleven'));
                    ?>
					</span>
				</li>

				<?php 
                } else {
                    ?>

				<li class="widget-entry-title">
					<?php 
                    // Grab first link from the post content. If none found, use the post permalink as fallback.
                    $link_url = twentyeleven_url_grabber();
                    if (empty($link_url)) {
                        $link_url = get_permalink();
                    }
                    ?>
					<a href="<?php 
                    echo esc_url($link_url);
                    ?>
" title="<?php 
                    printf(esc_attr__('Link to %s', 'twentyeleven'), the_title_attribute('echo=0'));
                    ?>
" rel="bookmark"><?php 
                    the_title();
                    ?>
&nbsp;<span>&rarr;</span></a>
					<span class="comments-link">
						<?php 
                    comments_popup_link(__('0 <span class="reply">comments &rarr;</span>', 'twentyeleven'), __('1 <span class="reply">comment &rarr;</span>', 'twentyeleven'), __('% <span class="reply">comments &rarr;</span>', 'twentyeleven'));
                    ?>
					</span>
				</li>

				<?php 
                }
                ?>

			<?php 
            }
            ?>
			</ol>
			<?php 
            echo $after_widget;
            // Reset the post globals as this query will have stomped on it
            wp_reset_postdata();
            // end check for ephemeral posts
        }
        $cache[$args['widget_id']] = ob_get_flush();
        wp_cache_set('widget_twentyeleven_ephemera', $cache, 'widget');
    }
Ejemplo n.º 4
0
/**
 * Return the first link from the post content. If none found, the
 * post permalink is used as a fallback.
 *
 * @since Twenty Eleven 1.0
 *
 * @uses get_url_in_content() to get the first URL from the post content.
 *
 * @return string The first link.
 */
function twentyeleven_get_first_url()
{
    $content = get_the_content();
    $has_url = function_exists('get_url_in_content') ? get_url_in_content($content) : false;
    if (!$has_url) {
        $has_url = twentyeleven_url_grabber();
    }
    //duplicate_hook
    return $has_url ? $has_url : apply_filters('the_permalink', get_permalink());
}