Question2answer:在RSS feed中显示摘录

There is a “Include full text in feeds:” option in the “RSS feeds” configuration panel but no options/method to only show excerpt instead of the “full text” or nothing for RSS feeds. This need to hack the question2answer source code. Details are in the answer.

“ RSS供稿”配置面板中有一个“在供稿中包含全文:”选项,但没有选项/方法仅显示摘录而不是“全文”,或没有供RSS供稿使用的选项/方法。 这需要破解question2answer 源代码 。 详细信息在答案中。

The changes based on Question2asnwer 1.5.4:

根据Question2asnwer 1.5.4进行的更改:

diff --git a/qa-include/qa-index.php b/qa-include/qa-index.php
index 1a5845a..f49d83c 100644
--- a/qa-include/qa-index.php
+++ b/qa-include/qa-index.php
@@ -158,7 +158,7 @@
                                                ob_start('ob_gzhandler');
                                                
                        if (substr($requestlower, 0, 5)=='feed/')
-                               require QA_INCLUDE_DIR.'qa-feed.php';
+                               require QA_INCLUDE_DIR.'qa-feed-excerpt.php';
                        else
                                require QA_INCLUDE_DIR.'qa-page.php';
                }
@@ -169,4 +169,4 @@
 
 /*
        Omit PHP closing tag to help avoid accidental output
-*/
 No newline at end of file
+*/


diff qa-feed.php qa-feed-excerpt.php 
40a41,74
> 	function qa_feed_excerpt($string, $length)
> /*
> 	Return no more than $length characters from $string after converting it to a single line, by
> 	removing words from the middle (and especially towards the end)
> */
> 	{
> 		$string=strtr($string, "rnt", '  ');
> 		
> 		if (qa_strlen($string)>$length) {
> 			$remaining=$length-5;
> 			
> 			$words=qa_string_to_words($string, false, true);
> 			$countwords=count($words);
> 			
> 			$prefix='';
> 			
> 			for ($addword=0; $addword<$countwords; $addword++) {
> 				$word=array_shift($words);
> 				
> 				if (qa_strlen($word)>$remaining)
> 					break;
> 				
> 				$prefix.=$word;
> 				
> 				$remaining-=qa_strlen($word);
> 			}
> 			
> 			$string=$prefix.' ... ';
> 		}
> 		
> 		return $string;
> 	}
> 
> 
402c436,438
< 			$lines[]='<description>'.qa_html($htmlcontent).'</description>'; // qa_html() a second time to put HTML code inside XML wrapper
---
> 			$lines[]='<description>'.
> 			qa_html(qa_feed_excerpt($htmlcontent, 400)).
> 			'</description>'; // qa_html() a second time to put HTML code inside XML wrapper
432c468
< */
 No newline at end of file
---
> */
Answered by SA.
由SA回答。


The patch for question2answer 1.6.3 can be downloaded here:

可在此处下载问题2answer 1.6.3的补丁

0001-qa-feed-excerpt-for-question2answer.patch.

0001-qa-feed-excerpt-forquestion2answer.patch

Note that I copied the qa-feed.php to qa-feed-excerpt.php before this patch.

请注意,在此补丁之前,我已将qa-feed.php复制到qa-feed-excerpt.php。

翻译自: https://www.systutorials.com/question2answer-show-excerpt-in-the-rss-feed/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值