Exemplo n.º 1
0
/**
 * Returns content stripped down and limited content.
 *
 * Strips out tags and shortcodes, limits the output to $max_char characters,
 * and appends an ellipses and more link to the end.
 *
 * @since 0.1.0
 *
 * @param integer $max_characters The maximum number of characters to return
 * @param string $more_link_text Optional. Text of the more link. Default is "(more...)"
 * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false
 * @return string Limited content
 */
function get_the_content_limit($max_characters, $more_link_text = '(more...)', $stripteaser = false)
{
    $content = get_the_content('', $stripteaser);
    /** Strip tags and shortcodes so the content truncation count is done correctly */
    $content = strip_tags(strip_shortcodes($content), apply_filters('get_the_content_limit_allowedtags', '<script>,<style>'));
    /** Inline styles / scripts */
    $content = trim(preg_replace('#<(s(cript|tyle)).*?</\\1>#si', '', $content));
    /** Truncate $content to $max_char */
    $content = genesis_truncate_phrase($content, $max_characters);
    /** More link? */
    if ($more_link_text) {
        $link = apply_filters('get_the_content_more_link', sprintf('%s <a href="%s" class="more-link">%s</a>', g_ent('&hellip;'), get_permalink(), $more_link_text), $more_link_text);
        $output = sprintf('<p>%s %s</p>', $content, $link);
    } else {
        $output = sprintf('<p>%s</p>', $content);
    }
    return apply_filters('get_the_content_limit', $output, $content, $link, $max_characters);
}
Exemplo n.º 2
0
/**
 * Outputs Post Title if option is selects
 *
 * @author Nick Croft
 * @since 0.1
 * @version 0.2
 * @param array $instance Values set in widget isntance
 */
function gfwa_do_post_title($instance)
{
    $link = $instance['link_title_field'] && genesis_get_custom_field($instance['link_title_field']) ? genesis_get_custom_field($instance['link_title_field']) : get_permalink();
    $wrap_open = $instance['link_title'] == 1 ? sprintf('<a href="%s" title="%s">', $link, the_title_attribute('echo=0')) : '';
    $wrap_close = $instance['link_title'] == 1 ? '</a>' : '';
    if (!empty($instance['show_title']) && !empty($instance['title_limit'])) {
        printf('<h2>%s%s%s%s</h2>', $wrap_open, genesis_truncate_phrase(the_title_attribute('echo=0'), $instance['title_limit']), $instance['title_cutoff'], $wrap_close);
    } elseif (!empty($instance['show_title'])) {
        printf('<h2>%s%s%s</h2>', $wrap_open, the_title_attribute('echo=0'), $wrap_close);
    }
}
 /**
  * Echo the widget content.
  *
  * @since  1.0.0
  *
  * @param  array $args Display arguments including before_title, after_title, before_widget, and after_widget.
  * @param  array $instance The settings for the particular instance of the widget
  *
  * @global mixed $wp_query
  */
 function widget($args, $instance)
 {
     /** Extract arguments */
     extract($args);
     /** Merge with defaults */
     $instance = wp_parse_args((array) $instance, $this->defaults);
     /** Check SPECIFIC display option for this widget and optionally disable it from displaying */
     if ($instance['not_in_public'] && !is_user_logged_in()) {
         return;
     }
     /** Check GENERAL display option for this widget and optionally disable it from displaying */
     if ('single_posts' === $instance['widget_display'] && !is_singular('post') || 'single_pages' === $instance['widget_display'] && !is_singular('page') || 'single_posts_pages' === $instance['widget_display'] && !is_singular(array('post', 'page'))) {
         return;
     }
     // end-if widget display checks
     /** Get global $wp_query object */
     global $wp_query;
     /** Widget title URL helpers */
     $title_url_custom = !empty($instance['title_url']) && !$instance['title_url_page'] ? $instance['title_url'] : '';
     $title_url = $instance['title_url_page'] ? get_permalink($instance['page_id']) : $title_url_custom;
     /** Optional title URL target */
     $title_url_target = $instance['title_url_target'] ? ' target="_blank"' : '';
     /** Typical WordPress Widget title filter */
     $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     /** GFPE Widget title filter */
     $title = apply_filters('gfpe_filter_widget_title', $instance['title'], $instance, $this->id_base);
     /** Prepare the title display string */
     $title_display = sprintf('%1$s%2$s%3$s', $instance['title_url_page'] || !empty($instance['title_url']) ? '<a href="' . esc_url($title_url) . '"' . $title_url_target . '>' : '', esc_attr($instance['title']), $instance['title_url_page'] || !empty($instance['title_url']) ? '</a>' : '');
     /** Output the widget wrapper and title */
     echo $before_widget;
     /** Set up the complete title display */
     if (empty($instance['title_hide']) && !empty($instance['title'])) {
         echo $before_title . $title_display . $after_title;
     }
     // end if
     /** Action hook 'gfpe_before_search_widget' */
     do_action('gfpe_before_page_widget', $instance, $this->id_base);
     /** Display widget intro text if it exists */
     if (!empty($instance['intro_text'])) {
         printf('<div class="textwidget"><p class="%s-intro-text gfpe-intro-text">%s</p></div>', $this->id, $instance['intro_text']);
     }
     // end-if optional intro
     /** Set new WP_Query instance */
     $wp_query = new WP_Query(array('page_id' => $instance['page_id']));
     /** Loop through pages */
     if (have_posts()) {
         while (have_posts()) {
             the_post();
             /** Genesis markup: open */
             genesis_markup(array('html5' => '<article %s>', 'xhtml' => sprintf('<div class="%s">', implode(' ', get_post_class())), 'context' => 'entry'));
             /**
              * Image center alignment helper - needs to go before actual
              *    image if/else statement!
              */
             if ('aligncenter' === $instance['image_alignment']) {
                 $img_centered = ' centered';
                 add_filter('genesis_attr_entry-image-widget', 'ddw_gfpe_entry_image_widget_class');
             } else {
                 $img_centered = '';
             }
             // end if
             /** a) Featured image support */
             if (!empty($instance['image_show']) && empty($instance['image_url'])) {
                 /** Retrieve featured image */
                 $image = genesis_get_image(array('format' => 'html', 'size' => $instance['image_size'], 'context' => 'featured-page-widget', 'attr' => genesis_parse_attr('entry-image-widget')));
                 /** Output featured image */
                 if ($image) {
                     printf('<%1$s %2$s title="%3$s" class="%4$s%5$s">%6$s</%1$s>', $instance['image_link'] ? 'a' : 'span', $instance['image_link'] ? 'href="' . get_permalink() . '"' : '', the_title_attribute('echo=0'), esc_attr($instance['image_alignment']), $img_centered, $image);
                 }
                 // end if
             } elseif (!empty($instance['image_url'])) {
                 $img_sizes = genesis_get_image_sizes();
                 // all image sizes available
                 $size_wh = $instance['image_size'];
                 // needed size (set in widget)
                 $custom_image = '<img width="' . absint($img_sizes[$size_wh]['width']) . '" height="' . absint($img_sizes[$size_wh]['height']) . '" src="' . esc_url($instance['image_url']) . '" class="attachment-' . $size_wh . $img_centered . '" alt="' . the_title_attribute('echo=0') . '" />';
                 printf('<%1$s %2$s title="%3$s" class="%4$s%5$s">%6$s</%1$s>', $instance['image_link'] ? 'a' : 'span', $instance['image_link'] ? 'href="' . esc_url(get_permalink()) . '"' : '', the_title_attribute('echo=0'), esc_attr($instance['image_alignment']), $img_centered, $custom_image);
             }
             // end if
             /** Page title support */
             if (!empty($instance['page_title_show'])) {
                 if (!empty($instance['page_title_limit'])) {
                     $page_title = genesis_truncate_phrase(the_title_attribute('echo=0'), $instance['page_title_limit']) . $instance['page_title_cutoff'];
                 } else {
                     $page_title = get_the_title();
                 }
                 // end if
                 $page_link = sprintf('<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute('echo=0'), $page_title);
                 /** Genesis 2.0+ / HTML5 way: */
                 if (genesis_html5()) {
                     printf('<header class="entry-header"><h2 class="entry-title">%s</h2></header>', !$instance['page_title_link'] ? $page_title : $page_link);
                 } else {
                     printf('<h2>%s</h2>', !$instance['page_title_link'] ? $page_title : $page_link);
                 }
                 // end if
             }
             // end if
             /** Page Byline support */
             if (!empty($instance['byline_show']) && !empty($instance['page_post_info'])) {
                 printf(genesis_html5() ? '<p class="entry-meta">%s</p>' : '<p class="byline post-info">%s</p>', do_shortcode($instance['page_post_info']));
             }
             // end if
             /** Set optional "autark" custom 'More Link' */
             $more_link_target = 'none' != $instance['more_link_target'] ? ' target="' . esc_html($instance['more_link_target']) . '"' : '';
             $autark_more_link = sprintf('<div class="gfpe-more-link"><a class="more-link%s" href="%s"%s title="%s">%s</a></div>', !empty($instance['more_link_class']) ? ' ' . esc_attr($instance['more_link_class']) : '', empty($instance['more_link_url']) ? get_permalink($instance['page_id']) : esc_url($instance['more_link_url']), $more_link_target, esc_html($instance['more_link_text']), $instance['more_link_text']);
             /**
              * 1) Content Type: Original Page Content (optional with wpautop!)
              */
             if ('page_content' === $instance['content_type']) {
                 echo genesis_html5() ? '<div class="entry-content">' : '';
                 /** a) No content limit is set: */
                 if (empty($instance['content_limit'])) {
                     global $more;
                     $more = 0;
                     printf('%s', $instance['page_keep_wpautop'] ? wpautop(the_content()) . $autark_more_link : get_the_content() . $autark_more_link);
                 } else {
                     printf('%s', empty($instance['more_link_url']) ? the_content_limit((int) $instance['content_limit'], esc_html($instance['more_link_text'])) : the_content_limit((int) $instance['content_limit'], '') . $autark_more_link);
                 }
                 // end if
                 echo genesis_html5() ? '</div>' : '';
             }
             // end if
             /**
              * 2) Content Type: Original Page Excerpt
              */
             if ('page_excerpt' === $instance['content_type']) {
                 echo genesis_html5() ? '<div class="entry-content">' : '';
                 printf(the_excerpt() . '%s', empty($instance['more_link_show']) ? '' : $autark_more_link);
                 echo genesis_html5() ? '</div>' : '';
             }
             // end if
             /**
              * 3) Content Type: Custom Text by user
              */
             if ('custom_user_content' === $instance['content_type']) {
                 echo '<div class="entry-content custom-content">';
                 $content = apply_filters('widget_text', empty($instance['custom_content']) ? '' : $instance['custom_content'], $instance);
                 echo $instance['custom_wpautop'] ? wpautop($content) : $content;
                 echo '</div>';
                 if (!empty($instance['more_link_text'])) {
                     echo $autark_more_link;
                 }
                 // end if
             }
             // end if
             /**
              * 4) Content Type: no content at all
              */
             if ('no_content' === $instance['content_type']) {
                 if ($instance['more_link_text']) {
                     echo $autark_more_link;
                 }
                 // end if
             }
             // end if
             /** Genesis markup: close */
             genesis_markup(array('html5' => '</article>', 'xhtml' => '</div><!--end post_class()-->' . "\n\n"));
         }
         // end while (when pages exist)
     }
     // end if loop check
     /** Display widget outro text if it exists */
     if (!empty($instance['outro_text'])) {
         printf('<div class="textwidget"><p class="%s-outro_text gfpe-outro-text">%s</p></div>', $this->id, $instance['outro_text']);
     }
     // end-if optional outro
     /** Action hook 'gfpe_after_search_widget' */
     do_action('gfpe_after_search_widget', $instance, $this->id_base);
     /** Output the closing widget wrapper */
     echo $after_widget;
     /** Reset our custom $wp_query object */
     wp_reset_query();
 }
Exemplo n.º 4
0
function scwd_trim_excerpt($text = '', $length = 0)
{
    global $post;
    //printr_f($post);
    if ($length === 0) {
        $length = apply_filters('scwd_excerpt_length', (int) genesis_get_option('content_archive_limit'));
    }
    if ('' === $text) {
        $text = get_the_content();
        $text = apply_filters('the_content', $text);
    }
    $excerpt_length = $length;
    $text = str_replace('\\]\\]\\>', ']]&gt;', $text);
    $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
    $text = strip_tags($text, apply_filters('scwd_excerpt_allowed_tags', '<p><span><div><a><br></br>'));
    $text_length = mb_strlen($text);
    $text = genesis_truncate_phrase($text, $excerpt_length);
    if ($text) {
        if ($text_length > $excerpt_length) {
            $text .= '...';
        }
    }
    return $text;
}
 /**
  * Outputs Post Title if option is selected.
  *
  * @param array $instance The settings for the particular instance of the widget.
  */
 public static function do_post_title($instance)
 {
     //* Bail if empty show param
     if (empty($instance['show_title'])) {
         return;
     }
     //* Custom Link or Permalink
     $link = $instance['link_title'] && $instance['link_title_field'] && genesis_get_custom_field('link_title_field') ? genesis_get_custom_field('link_title_field') : get_permalink();
     //* Add Link to Title?
     $wrap_open = $instance['link_title'] == 1 ? sprintf('<a href="%s" title="%s">', $link, the_title_attribute('echo=0')) : '';
     $wrap_close = $instance['link_title'] == 1 ? '</a>' : '';
     if (!empty($instance['title_limit'])) {
         $title = genesis_truncate_phrase(the_title_attribute('echo=0'), $instance['title_limit']) . $instance['title_cutoff'];
     } else {
         $title = the_title_attribute('echo=0');
     }
     if (genesis_html5()) {
         $hclass = apply_filters('gsfc_entry_title_class', ' class="entry-title"');
     } else {
         $hclass = '';
     }
     $pattern = apply_filters('gsfc_post_title_pattern', '<h2%s>%s%s%s</h2>');
     printf($pattern, $hclass, $wrap_open, $title, $wrap_close);
 }
Exemplo n.º 6
0
 /**
  * Outputs Post Title if option is selects
  *
  * @param array $instance The settings for the particular instance of the widget.
  */
 public static function do_post_title($instance)
 {
     //* Bail if empty show param
     if (empty($instance['show_title'])) {
         return;
     }
     //* Custom Link or Permalink
     if (empty($instance['link_title_field'])) {
         $link = get_permalink();
     } else {
         $link = $instance['link_title_field'];
     }
     //* Add Link to Title?
     $wrap_open = $instance['link_title'] == 1 ? sprintf('<a href="%s" title="%s">', esc_url($link), the_title_attribute('echo=0')) : '';
     $wrap_close = $instance['link_title'] == 1 ? '</a>' : '';
     if (!empty($instance['title_limit'])) {
         $title = genesis_truncate_phrase(the_title_attribute('echo=0'), $instance['title_limit']) . $instance['title_cutoff'];
     } else {
         $title = the_title_attribute('echo=0');
     }
     if (genesis_html5()) {
         $hclass = apply_filters('thememix_featured_content_entry_title_class', ' class="entry-title"');
     } else {
         $hclass = '';
     }
     global $thememix_featured_content_key;
     $thememix_featured_content_key = str_replace('featured-content-', '', $instance['widget_args']['widget_id']);
     $pattern = apply_filters('thememix_featured_content_post_title_pattern', '<h2%s>%s%s%s</h2>');
     $title = sprintf($pattern, $hclass, $wrap_open, $title, $wrap_close);
     $title = apply_filters('thememix_featured_content_post_title_add_extra', $title);
     echo $title;
 }
 /**
  * Home Content Limit function.
  *
  * @since 1.0.1
  *
  * @package GenesisFeaturedPageStaticWidget
  */
 function get_the_home_content_limit($max_characters, $more_link_text = '(more...)', $stripteaser = false)
 {
     $postspage = get_option('page_for_posts');
     $postspagecontent = get_post($postspage)->post_content;
     $postspagelink = get_permalink($postspage);
     //* Strip tags and shortcodes so the content truncation count is done correctly
     $content = strip_tags(strip_shortcodes($postspagecontent), apply_filters('get_the_content_limit_allowedtags', '<script>,<style>'));
     //* Remove inline styles / scripts
     $content = trim(preg_replace('#<(s(cript|tyle)).*?</\\1>#si', '', $content));
     //* Truncate $content to $max_char
     $content = genesis_truncate_phrase($content, $max_characters);
     //* More link?
     if ($more_link_text) {
         $link = apply_filters('get_the_content_more_link', sprintf('&#x02026; <a href="%s" class="more-link">%s</a>', $postspagelink, $more_link_text), $more_link_text);
         $output = sprintf('<p>%s %s</p>', $content, $link);
     } else {
         $output = sprintf('<p>%s</p>', $content);
         $link = '';
     }
     echo apply_filters('get_the_home_content_limit', $output, $content, $link, $max_characters);
 }