私は2つのDrupalアグリゲーターブロックを私のページに持っています.1つはTwitterフィード用、もう1つはブログフィード用です。これらは両方ともわずかに異なる方法で情報を提供します。Drupalアグリゲーターと調整済み出力
私はブログのフィードにタイトルを表示してから、ポストの最初の80文字をティーザーとして表示したいと思います。
私はTwitterフィードに説明を表示したいだけです。これは、タイトルがステータスへのリンク全体であるのに対して、説明は標準テキストに記載され、その中に含まれているURLをリンクするためです。私のブログのフィードに最適です
function mythemename_aggregator_block_item($item, $feed = 0) {
// Target p, div and images and preg_replace them with nothing
$tagstoreplace[0] = '/<p>/';
$tagstoreplace[1] = '/<div(.*?)>(.*?)<\/div>/im';
$tagstoreplace[2] = '/<img[^>]*>/';
// Generate output
$output = '<p class="feed-item-title"><a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a></p>\n";
$output .= '<p class="feed-item-description">' . substr(preg_replace($tagstoreplace, '', $item->description),0,80) . '...</p>';
return $output;
}
、完璧:
はこれまでのところ、私はこれを持っています。しかし、それは明らかに80文字に私のツイッターのフィードをカットします。私は140文字の妥協を試みましたが、それはHTMLであり、すべて<a href="..."></a>
はstrlen()
に含まれています。実際には実行できません。特にブログの説明があまりにも長くなる。
最後に、私の質問はこれです:私はそれを供給したいアグリゲータフィードに応じて出力を調整できますか?
これは、ページのコンテナdivのIDを取得することでこれを行うことを考えましたが、そのように見えません。
function mythemename_aggregator_block_item($item, $feed = 0) {
// Target p, div and images and preg_replace them with nothing
$tagstoreplace[0] = '/<p>/';
$tagstoreplace[1] = '/<div(.*?)>(.*?)<\/div>/im';
$tagstoreplace[2] = '/<img[^>]*>/';
// Get feed type
$blog = //something;
$twitter = //something;
// Generate output
if($blog) {
$output = '<p class="feed-item-title"><a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a></p>\n";
$output .= '<p class="feed-item-description">' . substr(preg_replace($tagstoreplace, '', $item->description),0,80) . '...</p>';
}
if($twitter) { $output .= '<p class="feed-item-description">' . $item->description . '</p>'; }
return $output;
この質問の長さについては申し訳ありません
と忍耐に感謝:理想的には、私はこのようなコードになってしまいます!