bbPressサイトにメタdescriptionとkeywordsを付けてみた
自分用にシンプルに
フロントページここから
<?php if ( bb_is_front()) {?>
<meta name="description" content="サイトの説明"/>
<meta name="keywords" content="キーワード,キーワード,キーワード"/>
<?php }?>
フロントページおわり
トピックページここから
<?php
if ($posts) {
foreach ($posts as $bb_post) : $del_class = post_del_class();
$old=ob_get_contents(); ob_clean(); ob_start(); // you may leave ob_start();
post_text();
$out.=ob_get_contents(); ob_clean();
endforeach;
$out = preg_replace('#<p[^>]*>(\s| ?)*</p>#', '', $out); // takes out <p>
$out = substr($out,0,200); // only displays the first 200 lines of the first post.
echo '<meta name="description" content="';
echo $out;
echo '">';
}
global $tags;
if (!empty($tags)) {
$keywords=""; foreach ($tags as $t) {$keywords.=$t->raw_tag.', ';}
echo "\n".'<meta name="keywords" content="'.trim($keywords,", ").'">'."\n"; // This displays any tags associated with that post as a keyword
} ?>
あ
トピックページおわり
global $tags;のところからメタキーワードですが、自分のbbPressはタグ機能を外してるので
<?php if ( bb_is_front()) {?>
<meta name="description" content="サイトの説明"/>
<meta name="keywords" content="キーワード,キーワード,キーワード"/>
<?php }?>
<?php if (bb_is_topic())
>
<?php
if ($posts) {
foreach ($posts as $bb_post) : $del_class = post_del_class();
$old=ob_get_contents(); ob_clean(); ob_start(); // you may leave ob_start();
post_text();
$out.=ob_get_contents(); ob_clean();
endforeach;
$out = preg_replace('#<p[^>]*>(\s| ?)*</p>#', '', $out); // takes out <p>
$out = substr($out,0,200); // only displays the first 200 lines of the first post.
echo '<meta name="description" content="';echo $out;
echo '"/>';
} ?>
<meta name="keywords" content="キーワード, キーワード, キーワード, <?php echo topic_title(); ?>, <?php echo forum_name(); ?>"/>
<?php endif;?>
フロントページとトピックページにのみ表示。
トピックページは、キーワードとトピックタイトル、フォーラム名を表示させる事に
サンプル
バンドメンバー募集bmbbb