wordpress函数手册_wordpress 摘要函数 wordpress 函数手册

怎么让WordPress首页显示文章摘要

方法一:修改WordPress文件。

优点:操作简单。

缺点:博客升级后会失效,需重新修改。

找到WorsPress目录wp-includes下formating.php文件,查找unction wp_trim_excerpt($text)函数,再找到excerpt_length,默认值是55,修改成需要的值即可。

方法二:自定义函数,修改主题function.php文件。

(楼主推荐)优点:一劳永逸。

缺点:换主题后需要重新设置。

The_excerpt()在Wordpress中,默认是截取55个英文单词的,但是在中文中却是无法截取到55个汉字。

原因是因为在wordpress的the_excerpt()函数中用到了1$text = implode(' ', $words);在php中是用空格来截取字数的,而我们汉字就杯具了,因为我们汉字是相连的,没有空格来区分,所以在使用中文的时候,经常地我们使用the_excerpt()函数的时候,截取出来的结果是全文!对于这个情况我们可以用PHP函数mb_substr去解决。

所以在Wordpress中可以打开主题中的funtions.php,加入下面的代码:12345function chinese_excerpt($text, $lenth=100) {$text = mb_substr($text,0, $lenth);return $text;}add_filter('the_excerpt', ' chinese_excerpt ');我这里设置默认的截取长度是100个字符,50个汉字。

可以在上面的代码中的$lenth=100设定为任意的截取长度。

或者直接使用中文截取法,加入如下代码12345function custom_excerpt_length( $length ) {return 200;}add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );200为字数,可以修改为自己的值。

需要安装服务器打开php mb_string扩展。

1、安装php-mbstrin扩展,终端执行。

sudo yum install php-mbstring。

2、切换root用户。

sudo -s3、修改php.ini,终端执行。

echo 'extension=mbstring.so' >>/etc/php.ini 4、重启web服务器。

apache:sudo service httpd restartnginx:sudo service nginx reload

wordpress最近文章分类中如何显示文章摘要

首先,到wordpress后台,依次选择?外观-->编辑-->选择右边的index.php文件,在里面可以看到语句 其次可以看出,index.php是嵌套一个?content.php?的文件用于专门显示文章的内容,这就是为什么在首页老是显示文章全文。

那么,打开content.php文件找到 →',?'twentyeleven'?)?);? ?> 将它修改为 最后,保存,就显示摘要了。

各位大神,推荐一个wordpress"阅读全文"的插件吧?

阅读全文不需要插件,直接在循环中添加就可以了或者也可以在function.php文件中编写替换函数,替换掉默认摘要function excerpt_read_more_link($output) {global $post;$output = excerptformat(mb_substr($output,0, 300));return $output;}add_filter('the_excerpt', 'excerpt_read_more_link');在上文中找到return $output; 然后添加修饰

wordpress首页如何调用最新文章

'id' ).com/zhidao/pic/item/023b5bb5c9ea15ce7ed3d214bf003af33a87b2e9.jpg" target="_blank" title="点击查看大图" class="ikqb_img_alink">add_filter(' ''orderby' shortcode_atts( array( '( ;figcaption' ;, '=> $html5 ;); , ' '; $post = gallery' , 'html5''link' intval( $atts['=> ' get_post(); $html5 = 'dd' exclude'columns' if&nbsp://a图片信息实际仍存储在posts表中;? ',不过可以通过其他字段实现啊 如下图;), &nbsp.php文件里的gallery_shortcode函数来重构gallery的输出 在functions.php中添加代码如下;function&nbsp: &nbsp,在alt text字段里填上该图片的外链 接着;0.hiphotos.baidu.com/zhidao/wh%3D600%2C800/sign=72292ad8e9fe9925cb596156049872e7/023b5bb5c9ea15ce7ed3d214bf003af33a87b2e9,需要参考wp-includes/media; my_post_gallery( 'itemtag' =&gt.jpg" esrc="http;'thumbnail'; &nbsp://a; &nbsp! empty( $atts['include'] ) ) { $_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); $attachments = array(); foreach ( $_attachments as $key => $val ) { $attachments[$val->ID] = $_attachments[$key]; } } elseif ( ! empty( $atts['exclude'] ) ) { $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); } else { $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) ); } if ( empty( $attachments ) ) { return ''; } if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id => $attachment ) { $output .= wp_get_attachment_link( $att_id, $atts['size'], true ) . "\n"; } return $output; } $itemtag = tag_escape( $atts['itemtag'] ); $captiontag = tag_escape( $atts['captiontag'] ); $icontag = tag_escape( $atts['icontag'] ); $valid_tags = wp_kses_allowed_html( 'post' ); if ( ! isset( $valid_tags[ $itemtag ] ) ) { $itemtag = 'dl'; } if ( ! isset( $valid_tags[ $captiontag ] ) ) { $captiontag = 'dd'; } if ( ! isset( $valid_tags[ $icontag ] ) ) { $icontag = 'dt'; } $columns = intval( $atts['columns'] ); $itemwidth = $columns > 0 ? floor(100/$columns) : 100; $float = is_rtl() ? 'right' : 'left'; $selector = "gallery-{$instance}"; $gallery_style = ''; /** * Filters whether to print default gallery styles. * * @since 3.1.0 * * @param bool $print Whether to print default gallery styles. * Defaults to false if the theme supports HTML5 galleries. * Otherwise, defaults to true. */ if ( apply_filters( 'use_default_gallery_style', ! $html5 ) ) { $gallery_style = " #{$selector} { margin: auto; } #{$selector} .gallery-item { float: {$float}; margin-top: 10px; text-align: center; width: {$itemwidth}%; } #{$selector} img { border: 2px solid #cfcfcf; } #{$selector} .gallery-caption { margin-left: 0; } /* see gallery_shortcode() in wp-includes/media.php */ \n\t\t"; } $size_class = sanitize_html_class( $atts['size'] ); $gallery_div = ""; /** * Filters the default gallery shortcode CSS styles. * * @since 2.5.0 * * @param string $gallery_style Default CSS styles and opening HTML div container * for the gallery shortcode output. */ $output = apply_filters( 'gallery_style', $gallery_style . $gallery_div ); $i = 0; foreach ( $attachments as $id => $attachment ) { $attr = ( trim( $attachment->post_excerpt ) ) ? array( 'aria-describedby' => "$selector-$id" ) : ''; if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) { $image_output = wp_get_attachment_link( $id, $atts['size'], false, false, false, $attr ); } elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) { $attr['alt'] = get_the_title($post->ID); $image_output = wp_get_attachment_image( $id, $atts['size'], false, $attr ); $custom_link = trim( strip_tags( get_post_meta( $id, '_wp_attachment_image_alt', true ) ) ); $image_output = sprintf( '%s', $custom_link, $attr['alt'], $image_output ); } else { $image_output = wp_get_attachment_link( $id, $atts['size'], true, false, false, $attr ); } $image_meta = wp_get_attachment_metadata( $id ); $orientation = ''; if ( isset( $image_meta['height'], $image_meta['width'] ) ) { $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape'; } $output .= ""; $output .= " $image_output "; if ( $captiontag && trim($attachment->post_excerpt) ) { $output .= "

摘要函数?

1、打开wordpress网站,登录后台2、在打开的wordpress网站后台仪表盘,将鼠标移动到设置3、在出现的设置子菜单中,打开 阅读4、在阅读设置中,可以对首页显示的内容进行设定5、最重要的在下面,把feed中的每篇文章,显示设置为 摘要,然后保存更改6、回到首页,刷新一下,是不是看到了一篇篇文章变成了自留地一样的长条条,更便于用户浏览了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值