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
    } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题