首页 » 成都SEO论坛 » 摆龙门阵

bbpress的meta属性怎么调用?

(共有4层楼)
  • 永久链接:http://yeeseo.com/discuss/topic/151
  • lowkey 发表于 1 年前
  • 最新回复来自 lowkey
  1. 国内关于bbpress的资料实在是太少了,我好不容易弄好了插件和主题,却发现meta description的调用出现了问题。

    百度之后,我还是啥都没有看到,只好用有道词典配合下去看下国外的资料,找到两个方法,但是我估计还得再修改下:

    第一,在head区域加上这个,我尝试过,先不说版块的描述只能调用的默认设置的,(估计翻页也是一样)描述里面没有成功的去掉<p>标签,还出现了些许乱码。

    <?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 '">';
    }
    else {
    echo '<META NAME="Description" CONTENT="This is your defalt description edit this to what ever you want ">'; // This displays when where is no post
    }
    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
    } ?>

    第二,看到一个回帖说bbpress本身有函数支持的。(no need for all that object-based markey, bbPress has functions to pass as a string rather than echo...)

    <?php
    /*
    Plugin Name: Meta Headers
    */

    function meta_heads() {

    global $posts, $tags;

    if ( $posts ) {
    $out = $posts[0]->post_text;
    $out = strip_tags( $out );
    $out = str_replace( array( "\n", "\r" ), ' ', $out );
    $out = substr($out, 0, 200); // only display the first 200 characters of the first post
    }

    if( empty( $out ) )
    $out = 'Default description';

    echo "\n".'<meta name="description" content="'.$out.'" />';

    if ( !empty( $tags ) ) {
    $keywords = '';
    foreach ($tags as $t) {
    $keywords.=$t->raw_tag.', ';
    }
    echo "\n".'<meta name="keywords" content="'.substr($keywords,0,-2).'">'."\n"; // displays any tags associated with a topic as keywords
    }

    }

    add_action( 'bb_head', 'meta_heads' );

    这个我不晓得怎么用,bbpress模板文章里面没有找到function文件,是不是我要新建一个?易优老师,你又是怎么实现的呢?

    发表于 1 年前 #
  2. 有个插件,叫bbpress seo tool,第二个问题,没听懂。。。囧

    发表于 1 年前 #
  3. 哦,对了,再抛出个问题:

    永久链接:http://yeeseo.com/discuss/topic/151 这是通过什么函数?我尝试用跟wordpress一样的函数调用,结果失败了。

    发表于 1 年前 #
  4. 我昨天也下载了这个插件,我也启用了,后台出现了seo tool 设置,我保存之后没有发现帖子代码中出现meta description属性,真不知道哪里出现了问题。

    昨天我下载的时候,看到老外有所bbpress1.x多的版本不支持之前的seo tool 插件,但是我昨天使用那个人提供的这个插件也是一样的反应,我重新把原本主题的header.php上传,结果成功了,残念,之前我修改了header.php部分,发现问题之后我替换了两次,还是没事显示,应该就是之前我替换错误的缘故。

    我第二个问题的意思是怎么调用 这个永久链接:http://yeeseo.com/discuss/topic/151函数,就是在文件里面写什么函数才能调用出帖子的永久链接,我尝试过通过wordpress的那个调用文章的固定链接函数来实现,但是报错了。

    在模板中添加什么才能显示出帖子的固定链接呢?

    发表于 1 年前 #

回复

您需要 登录 才能发帖