找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
积分等级发帖收益的说明江阴论坛帮助汇总江阴论坛管理规则(必看)江阴论坛版主招聘中江阴论坛已运行
查看: 1506|回复: 0

[WordPress] 自动摘要的方法

[复制链接]
发表于 2010-4-15 12:37:50 | 显示全部楼层 |阅读模式
修改 functions.php 文件
  1. function my_excerpts($content = false) {
  2.         // If is the home page, an archive, or search results
  3.         if(is_front_page() || is_archive() || is_search()) :
  4.                 global $post;
  5.                 $content = $post->post_excerpt;

  6.         // If an excerpt is set in the Optional Excerpt box
  7.                 if($content) :
  8.                         $content = apply_filters('the_excerpt', $content);

  9.         // If no excerpt is set
  10.                 else :
  11.                         $content = $post->post_content;
  12.                         $excerpt_length = 55;
  13.                         $words = explode(' ', $content, $excerpt_length + 1);
  14.                         if(count($words) > $excerpt_length) :
  15.                                 array_pop($words);
  16.                                 array_push($words, '...');
  17.                                 $content = implode(' ', $words);
  18.                         endif;
  19.                         $content = '<p>' . $content . '</p>';

  20.                 endif;
  21.         endif;

  22. // Make sure to return the content
  23.         return $content;

  24. }

  25. add_filter('the_content', 'my_excerpts');
复制代码
当设置摘要的时候,会显示摘要。没有的时候就自动提取摘要
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|江阴人家

GMT+8, 2024-4-27 01:47 , Processed in 0.021228 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表