当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_trim_words函数代码示例

本文整理汇总了PHP中wp_trim_words函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_trim_words函数的具体用法?PHP wp_trim_words怎么用?PHP wp_trim_words使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_trim_words函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: alaya_recent_comment

function alaya_recent_comment($number)
{
    $commentNum = 1;
    // Get the comments
    $recent_comments = get_comments(array('number' => $number, 'status' => 'approve', 'type' => 'comment'));
    $commentList = '<ul>';
    foreach ($recent_comments as $comment) {
        $commentList .= '<li>
	             <header class="clearfix">
	                	<figure>
	                        <a href="' . get_permalink($comment->comment_post_ID) . '">
	                            ' . get_avatar($comment->comment_author_email, '40') . '
	                        </a>
	                        <span class="comment-author-name">
	                        ' . $comment->comment_author . '
	                        </span>
	                        <div class="comment-order">' . $commentNum . '</div>
	                    </figure>
	                    
	                    <a class="comment-post" href="' . esc_url(get_permalink($comment->comment_post_ID)) . '#comment-' . esc_attr($comment->comment_ID) . '">
	                       ' . esc_attr(get_the_title($comment->comment_post_ID)) . '
	                    </a>
	                </header>
	                
	                <div class="comment-text">
	                    <div class="up-arrow"></div>
	                	' . wp_trim_words($comment->comment_content, 30) . '
	                </div>
				</li>';
        $commentNum++;
    }
    $commentList .= '</ul>';
    return $commentList;
}
开发者ID:jasmith93,项目名称:cnws,代码行数:34,代码来源:widgets-func.php

示例2: cap_podcast_player

/**
* We're going to override the_content through a filter.
*/
function cap_podcast_player($id = null, $player_type = 'default')
{
    if (empty($id)) {
        $post_id = get_the_ID();
    } else {
        $post_id = $id;
    }
    $episode_number = get_post_meta($post_id, 'episode_number', true);
    // Get Episode Media Source
    $episode_attachment_id = get_post_meta($post_id, 'episode_file', true);
    $episode_external_file = get_post_meta($post_id, 'external_episode_file', true);
    if (!empty($episode_attachment_id)) {
        $player_src = wp_get_attachment_url($episode_attachment_id);
    } elseif (!empty($episode_external_file)) {
        $player_src = $episode_external_file;
    }
    $attr = array('src' => '' . $player_src . '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata');
    $player = wp_audio_shortcode($attr);
    $download_link = '<small><a href="' . $player_src . '" download="episode' . $episode_number . '.mp3">Download this Episode</a></small>';
    // Get Episode Artwork //
    $episode_artwork_id = get_post_thumbnail_id($post_id);
    $episode_artwork = wp_get_attachment_image_src($episode_artwork_id, 'cap-podcast-thumbnail');
    $episode_artwork_src = $episode_artwork[0];
    if ('default' == $player_type) {
        $episode_title = '
        <div class="episode-info">
            <h4>Episode #' . $episode_number . '</h4>
            <h2>' . get_the_title($post_id) . '</h2>
        </div>
        ';
    } elseif ('large' == $player_type) {
        $post_object = get_post($post_id);
        $episode_title = '
        <a href="' . get_permalink($post_id) . '" class="episode-info">
            <h4>Episode #' . $episode_number . '</h4>
            <h2>' . get_the_title($post_id) . '</h2>
            <span class="description">' . wp_trim_words($post_object->post_content, '60') . '</span>
        </a>
        ';
    } elseif ('mini' == $player_type) {
        $episode_title = '';
    }
    // Construct Markup
    $markup = '
    <div class="episode-header">
        <div class="episode-artwork-container">
            <div class="episode-artwork" style="background-image: url(' . $episode_artwork_src . ');">
                <div id="play-episode" class="maintain-ratio">
                    <span class="dashicons"></span>
                </div>
            </div>
        </div>
        ' . $episode_title . '
    </div>';
    $script = "\n    <script type='text/javascript'>\n    var playerID = jQuery('#episode-" . $episode_number . "-" . $post_id . " audio').attr('id');\n    var player" . $post_id . " = document.getElementById(playerID);\n    jQuery('#episode-" . $episode_number . "-" . $post_id . " #play-episode').click(function(){\n        jQuery('#episode-" . $episode_number . "-" . $post_id . " #play-episode .dashicons').toggleClass('paused');\n    });\n\n    jQuery('#episode-" . $episode_number . "-" . $post_id . " #play-episode').click(function() {\n\n        if ( jQuery('#episode-" . $episode_number . "-" . $post_id . " #play-episode .dashicons').hasClass('paused') ) {\n            player" . $post_id . ".play();\n        }\n\n        if ( !jQuery('#episode-" . $episode_number . "-" . $post_id . " #play-episode .dashicons').hasClass('paused') ) {\n            player" . $post_id . ".pause();\n        }\n\n    });\n    </script>\n    ";
    if (function_exists('cap_podcast_player_colors')) {
        $player .= cap_podcast_player_colors($post_id);
    }
    return '<div id="episode-' . $episode_number . '-' . $post_id . '" class="podcast-player ' . $player_type . '">' . $markup . $player . $download_link . $script . '</div>';
}
开发者ID:amprog,项目名称:cap-podcaster,代码行数:63,代码来源:single-episode-template.php

示例3: get_top_downloads_home

/**
 * Function to retrive most downloaded software list for the home page
 *
 * @return array
 *
 */
function get_top_downloads_home()
{
    $limit = 5;
    $json_path = ABSPATH . "../top.json";
    $baixades_json = json_decode(file_get_contents($json_path));
    $programari = array();
    if ($baixades_json) {
        foreach ($baixades_json as $key => $operating_system) {
            $programari[$key] = array();
            $i = 0;
            foreach ($operating_system as $pkey => $program) {
                if ($i < $limit) {
                    $link = get_program_link($program);
                    if ($link) {
                        $programari[$key][$pkey]['title'] = wp_trim_words(str_replace('_', ' ', get_the_title($program->wordpress_id)), 8);
                        $programari[$key][$pkey]['link'] = $link;
                        $programari[$key][$pkey]['total_downloads'] = $program->total;
                    }
                    $i++;
                }
            }
        }
    }
    return $programari;
}
开发者ID:softcatala,项目名称:wp-softcatala,代码行数:31,代码来源:post_types_functions.php

示例4: uw_blogroll_shortcode

 function uw_blogroll_shortcode($atts = array())
 {
     //allow pagebuilder widgets to run the shortcode, block all other posts to prevent infinite loops
     if (get_post_type() == 'post' && !is_home()) {
         return '';
     }
     $params = array_merge(array('excerpt' => 'true', 'trim' => 'false', 'image' => 'hide', 'author' => 'show', 'titletag' => 'h2', 'number' => 5), $atts);
     if (!array_key_exists('numberposts', $params)) {
         $params['numberposts'] = $params['number'];
     }
     $posts = get_posts($params);
     foreach ($posts as $post) {
         if (!stripos($post->post_content, '[blogroll')) {
             //to prevent infinite loops in pagebuilder widgets
             $postID = $post->ID;
             $link = get_permalink($postID);
             if (in_array($params['excerpt'], array('show', 'true'))) {
                 $excerpt = strlen($post->post_excerpt) > 0 ? $post->post_excerpt : apply_filters('widget_text', $post->post_content);
                 if (in_array($params['trim'], array('show', 'true'))) {
                     $excerpt = wp_trim_words($excerpt);
                 }
                 $excerpt = wpautop($excerpt);
                 //using apply_filters('the_content', $excerpt) causes an infinite loop
                 if (in_array($params['image'], array('show', 'true'))) {
                     $image = get_the_post_thumbnail($postID, 'thumbnail', array('style' => 'float:left;padding-right:10px;'));
                     $class = 'class="pull-left"';
                 }
             }
             $author = $params['author'] === 'show' ? '<p class="author-info">' . get_the_author_meta('display_name', $post->post_author) . '</p>' : '';
             $postDate = get_the_time(get_option('date_format'), $postID);
             $html .= "<li {$class}>{$image}<span><p class=\"date\">{$postDate}</p><" . $params['titletag'] . "><a href=\"{$link}\">{$post->post_title}</a></" . $params['titletag'] . ">{$author}{$excerpt}</span></li>";
         }
     }
     return "<ul class=\"shortcode-blogroll\">{$html}</ul>";
 }
开发者ID:uw-sop,项目名称:htdocs,代码行数:35,代码来源:custom-shortcodes.php

示例5: tgp_get_products

function tgp_get_products()
{
    // Connect to the database
    $db = new wpdb(get_option('db_user'), get_option('db_pass'), get_option('db_name'), get_option('db_host'));
    // Get values
    $store_url = get_option('store_url');
    $img_folder = get_option('img_folder');
    $num_products = get_option('num_products');
    // Get Products
    $products = $db->get_results("SELECT * FROM products LIMIT " . $num_products);
    // Build Output
    $output = '';
    if ($products) {
        foreach ($products as $product) {
            $output .= '<div class="tgp_product">';
            $output .= '<h3>' . $product->title . '</h3>';
            $output .= '<img src="' . $store_url . '/' . $img_folder . '/' . $product->image . '" alt="' . $product->title . '">';
            $output .= '<div class="price">' . $product->price . '</div>';
            $output .= '<div class="desc">' . wp_trim_words($product->description, 10) . '</div>';
            $output .= '<a href="' . $store_url . 'products/details/' . $product->id . '">Buy Now</a>';
        }
    } else {
        $output .= 'No products to list';
    }
    return $output;
}
开发者ID:alt3red,项目名称:thegamingplace,代码行数:26,代码来源:thegamingplace.php

示例6: get_fb_posts

 function get_fb_posts($num, $truncate_words = false, $divs = true)
 {
     $posts = get_facebook_posts();
     $i = 1;
     foreach ($posts as $post) {
         if ($i > $num) {
             break;
         }
         if ($i < $num) {
             $i++;
             continue;
         }
         if (empty($post['content'])) {
             $post_content = $post['link_description'];
         } elseif (!empty($post['content'])) {
             $post_content = $post['content'];
         } else {
             $post_content = 'Enclothed - Men\'s bespoke outfitters';
         }
         $post_content = utf8_decode($post_content);
         $post_content = wp_trim_words($post_content, $truncate_words);
         $post_content = make_clickable($post_content);
         if ($divs) {
             echo "<div class='fb_post' style='padding-bottom:20px'>";
             echo "<div class='fb_post_content'>{$post_content}</div>";
             echo "</div>";
         } else {
             echo $post_content;
         }
         $i++;
     }
 }
开发者ID:roycocup,项目名称:enclothed,代码行数:32,代码来源:functions.php

示例7: ubermenu_recent_posts

function ubermenu_recent_posts($atts)
{
    global $uberMenu;
    extract(shortcode_atts(array('num' => 3, 'img' => 'on', 'img_size' => 'inherit', 'img_width' => 45, 'img_height' => 45, 'excerpt' => 'off', 'category' => '', 'default_img' => false, 'offset' => 0), $atts));
    $args = array('numberposts' => $num, 'offset' => $offset, 'suppress_filters' => false);
    if (!empty($category)) {
        if (is_numeric($category)) {
            $args['category'] = $category;
        } else {
            $args['category_name'] = $category;
        }
    }
    $posts = get_posts($args);
    $class = 'ubermenu-postlist';
    if ($img == 'on') {
        $class .= ' ubermenu-postlist-w-img';
    }
    $html = '<ul class="' . $class . '">';
    foreach ($posts as $post) {
        $ex = $post->post_excerpt;
        if ($ex == '' && function_exists('wp_trim_words')) {
            //wp_trim_words is a WP3.3 function
            $ex = $post->post_content;
            $ex = strip_shortcodes($ex);
            $ex = str_replace(']]>', ']]&gt;', $ex);
            $excerpt_length = apply_filters('excerpt_length', 55);
            $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
            $ex = wp_trim_words($ex, $excerpt_length, $excerpt_more);
        }
        //$ex = apply_filters('get_the_excerpt', $post->post_excerpt);
        $post_url = get_permalink($post->ID);
        $image = '';
        $w = $img_width;
        $h = $img_height;
        $content_styles = array();
        //if($img == 'on') $image = $uberMenu->getPostImage($post->ID, $w, $h, $default_img);
        if ($img == 'on') {
            $img_data = ubermenu_get_image(false, $post->ID, true, array('img_w' => $w, 'img_h' => $h, 'img_size' => $img_size, 'default_img' => $default_img));
            if (isset($img_data['img'])) {
                $image = $img_data['img'];
                $content_styles['padding-left'] = $img_data['w'] + 10 . 'px';
            }
        }
        $_content_styles = '';
        if (!empty($content_styles)) {
            $_content_styles = 'style="';
            foreach ($content_styles as $prop => $val) {
                $_content_styles .= $prop . ':' . $val . ';';
            }
            $_content_styles .= '"';
        }
        $html .= '<li class="ubermenu-postlist-item">' . $image . '<div class="ubermenu-postlist-title" ' . $_content_styles . '><a href="' . $post_url . '">' . $post->post_title . '</a></div>';
        if ($excerpt == 'on') {
            $html .= '<div class="ubermenu-postlist-content" ' . $_content_styles . '>' . $ex . '</div>';
        }
        $html .= '</li>';
    }
    $html .= '</ul>';
    return $html;
}
开发者ID:WackoMako,项目名称:stonedape,代码行数:60,代码来源:shortcodes.php

示例8: wp_aatags_run

function wp_aatags_run($post_ID)
{
    $tags = get_option('wp_aatags_opts');
    $number = get_option('wp_aatags_aadnumber');
    global $wpdb;
    if (get_post($post_ID)->post_type == 'post' && !wp_is_post_revision($post_ID) && !get_the_tags($post_ID)) {
        $post_title = get_post($post_ID)->post_title;
        $post_content = get_post($post_ID)->post_content;
        switch ($tags) {
            case 3:
                $requix = strtolower($post_title . ' ' . wp_trim_words($post_content, 333, ''));
                break;
            case 2:
                $requix = strtolower($post_title . ' ' . wp_trim_words($post_content, 999, ''));
                break;
            default:
                $requix = strtolower($post_title);
                break;
        }
        $body = wp_aatags_keycontents(wp_aatags_html2text($requix), $number);
        if ($body != 'rEr') {
            $keywords = wp_aatags_kwsiconv($body);
            wp_add_post_tags($post_ID, $keywords);
        } else {
            wp_aatags_alts($post_ID, $post_title, $post_content);
        }
    }
}
开发者ID:yszar,项目名称:linuxwp,代码行数:28,代码来源:wp-autotags.php

示例9: get_shortened_string

 /**
  * Returns shortened string
  *
  * @since     1.0
  */
 protected function get_shortened_string($string = '', $num_words = 55, $more = null)
 {
     if (!$string) {
         return false;
     }
     return wp_trim_words($string, $num_words, $more);
 }
开发者ID:adisonc,项目名称:MaineLearning,代码行数:12,代码来源:values.php

示例10: vcex_get_excerpt

 function vcex_get_excerpt($length = 30, $readmore = false, $read_more_text = '', $post_id = '')
 {
     global $post;
     $id = $post_id ? $post_id : $post->ID;
     $custom_excerpt = apply_filters('the_content', $post->post_excerpt);
     if ($custom_excerpt) {
         $output = $custom_excerpt;
     } else {
         $meta_excerpt = get_post_meta($id, 'vcex_excerpt_length', true);
         $length = $meta_excerpt ? $meta_excerpt : $length;
         $read_more_text = $read_more_text ? $read_more_text : __('view post', 'vcex');
         $excerpt = get_the_content('');
         $excerpt = do_shortcode($excerpt);
         $excerpt = apply_filters('the_content', $excerpt);
         $excerpt = str_replace(']]>', ']]>', $excerpt);
         $excerpt = apply_filters('the_content', $excerpt);
         $excerpt = wp_trim_words($excerpt, $length);
         $excerpt = wp_kses($excerpt, array('a' => array('href' => array(), 'title' => array()), 'br' => array(), 'em' => array(), 'strong' => array()));
         $output = '<p>' . html_entity_decode($excerpt) . '</p>';
     }
     if ($readmore == true) {
         $readmore_link = '<a href="' . get_permalink($id) . '" title="' . __('View Post', 'vcex') . '" rel="bookmark" class="vcex-readmore theme-button">' . $read_more_text . ' <span class="vcex-readmore-rarr">&rarr;</span></a>';
         $output .= apply_filters('vcex_readmore_link', $readmore_link);
     }
     return $output;
 }
开发者ID:nhatnam1102,项目名称:wp-content,代码行数:26,代码来源:functions.php

示例11: evision_corporate_words_count

 function evision_corporate_words_count($length = 25, $evision_corporate_content = null)
 {
     $length = absint($length);
     $source_content = preg_replace('`\\[[^\\]]*\\]`', '', $evision_corporate_content);
     $trimmed_content = wp_trim_words($source_content, $length, '...');
     return $trimmed_content;
 }
开发者ID:karthikakamalanathan,项目名称:wp-cookieLawInfo,代码行数:7,代码来源:words-count.php

示例12: product_content_shortcode

 /**
  * Add a shortcode to display the product content
  *
  * @since 1.0
  */
 public function product_content_shortcode($atts, $content = null)
 {
     // Get our shortcode attributes
     $atts = shortcode_atts(array('id' => '', 'length' => ''), $atts, 'product_content');
     extract($atts);
     // Get our post content
     $product = get_post($id);
     // If there is no product found, stop
     if (!$product) {
         return;
     }
     $content = wpautop($product->post_content);
     // Assume zer is nussing
     $output = '';
     // If our content returns something, display it
     if ($content) {
         // If we have a length set, apply it
         if ('' !== $length) {
             $excerpt_length = $length;
             $excerpt_more = '&hellip;';
             $output .= '<p>' . wp_trim_words($content, $excerpt_length, $excerpt_more) . ' <a href="' . get_permalink($id) . '" class="more-link">' . __('Continue reading', 'etsy_importer') . ' <span class="screen-reader-text">' . $product->post_title . '</span></a></p>';
         } else {
             $output .= $content;
         }
     }
     return apply_filters('etsy_importer_product_content_shortcode', $output, $atts);
 }
开发者ID:jrogers1126,项目名称:Etsy-Product-Importer-for-WordPress,代码行数:32,代码来源:shortcodes.php

示例13: wp_trim_words

					<p>
						<?php 
        //var_dump(get_the_content().'---'.$length);
        echo wp_trim_words(get_the_content(), $length, '&hellip; <a href="' . get_permalink() . '">' . __('Read more', 'yatheme') . '</a>');
        ?>
						
					</p>
                    </div>
				</div>
			</div>
		<?php 
    }
    ?>
		</div>
		<?php 
}
function tabs_popular_posts($posts, $length)
{
    $popular = new WP_Query('orderby=comment_count&posts_per_page=' . $posts);
    //$popular_post_num = 1;
    ?>
		<div class="row-fluid tab-post">
		<?php 
    while ($popular->have_posts()) {
        $popular->the_post();
        ?>
			<div class="tab-item">
				<div class="row-fluid">
						<div class="comment">
							<?php 
        if ((int) get_post()->comment_count > 1) {
            echo get_post()->comment_count . ' ';
        } else {
开发者ID:pqzada,项目名称:avispate,代码行数:33,代码来源:default.php

示例14: save_report_item

 public static function save_report_item()
 {
     if (!isset($_POST[DLN_ABE_NONCE]) || !wp_verify_nonce($_POST[DLN_ABE_NONCE], DLN_ABE_NONCE)) {
         $item_id = isset($_POST['report_item_id']) ? $_POST['report_item_id'] : '';
         $category = isset($_POST['report_category']) ? (int) $_POST['report_category'] : '';
         $message = isset($_POST['report_reason']) ? $_POST['report_reason'] : '';
         $user_id = get_current_user_id();
         $message = esc_html($message);
         $title = wp_trim_words($message, 20, '...');
         if ($user_id && $item_id && $category && $message && $title) {
             $args = array('post_title' => $title, 'post_status' => 'pending', 'post_type' => 'dln_report', 'post_author' => $user_id, 'post_content' => $message, 'post_category' => array($category), 'comment_status' => 'open');
             $post_id = wp_insert_post($args);
             if ($post_id) {
                 // Get current user ip
                 $ip = !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
                 update_post_meta($post_id, 'dln_report_post_id', $item_id);
                 update_post_meta($post_id, 'dln_report_user_ip', $ip);
                 // Update count to post
                 $count = (int) get_post_meta($item_id, 'dln_count_report', true);
                 if ($count) {
                     update_post_meta($item_id, 'dln_count_report', $count + 1);
                 }
             }
         }
         exit($post_id);
     }
     exit('0');
 }
开发者ID:httvncoder,项目名称:151722441,代码行数:28,代码来源:report-ajax.php

示例15: pbosfc_post_excerpt

/**
 * Based (with preserved compatibility) on Storefront Blog Excerpts plugin.
 */
function pbosfc_post_excerpt()
{
    if (!pbosfc_get_option('post_excerpt')) {
        storefront_post_content();
    } else {
        ?>
		<div class="entry-content" itemprop="articleBody">
			<?php 
        if (has_post_thumbnail()) {
            $thumb_size = pbosfc_get_option('excerpt_image_size');
            if ($thumb_size !== 'none') {
                $img_class = $thumb_size == 'thumbnail' ? apply_filters('woa_sf_blog_excerpt_image_float', pbosfc_get_option('excerpt_image_float')) : '';
                the_post_thumbnail($thumb_size, array('itemprop' => 'image', 'class' => "attachment-{$thumb_size} {$img_class}"));
            }
        }
        $content = do_shortcode(has_excerpt(get_the_ID()) ? get_the_excerpt() : get_the_content());
        $content = wp_trim_words($content, pbosfc_get_option('excerpt_word_count'), __('...', 'pbosfc'));
        echo apply_filters('the_excerpt', $content);
        ?>
			<p class="read-more"><a class="button"
			                        href="<?php 
        the_permalink();
        ?>
"><?php 
        echo __('Continue reading', 'pbosfc');
        ?>
</a>
			</p>
		</div><!-- .entry-content -->
		<?php 
    }
}
开发者ID:boguslawski-piotr,项目名称:pbo-storefront-compact,代码行数:35,代码来源:post.php


注:本文中的wp_trim_words函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。