douyan6548 2012-05-09 03:08
浏览 45
已采纳

在单个帖子之外显示元描述 - WordPress

This is my first question here, hope to be useful in future to someone. We work on a WordPress site now, and try to display meta description content generated by All In One Seo plugin outside the loop. It's not a problem when it's on page/post. The code that works for single is

<?php $metadesc = get_post_meta($post->ID, '_aioseop_description', true);
if ($metadesc) {
echo $metadesc;
} else {
the_excerpt();
}
?>

Later on the other day I came with this solution

<?php $mykey_values = get_post_custom_values('_aioseop_description'); 
foreach ( $mykey_values as $key => $value ) {
echo "$value"; 
 } ?>

I'm not sure if it's good to use this one, the problem I have now is that I want to display exact number of symbols, not all the content.

  • 写回答

1条回答 默认 最新

  • doushi2845 2012-05-09 18:56
    关注

    Well it was pretty lame question, but sometimes when you are stuck it's hard to see simple things. This is my final code which do the work for me:

    <?php $mykey_values = get_post_custom_values('_aioseop_description');
    foreach ( $mykey_values as $key => $value ) {
    echo substr("$value",0 ,150); //This will display the first 150 symbols
    } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题