doushi1900 2018-08-07 14:10
浏览 44
已采纳

将数组数据传递给循环中的变量

How do I pass the contents of the $the_slug to the $post_name variable in the loop?

$tags = get_the_tags();
foreach ($tags as $tag){

global $post;
$the_slug = $tag->slug; //contains 10ish words that associate with my permalinks: welcome, home, about, contact, etc

$post_id = 'welcome';
$post_name = $the_slug; //fails to populate here
$queried_post = get_post($post_name); //if changed to $post_id works but only 'welcome' post
$excerpt = $queried_post->post_excerpt;
$excerpt = apply_filters('the_content', $excerpt);
$excerpt = str_replace(']]>', ']]>', $excerpt);
echo $excerpt . "

";
}

Thanx for looking.

  • 写回答

1条回答 默认 最新

  • doushaqing7080 2018-08-07 14:22
    关注

    You can iterate over the array with a foreach loop:

    foreach($the_slug as $slug){
       $post_name = $slug;
       $queried_post = get_post($post_name); $excerpt = $queried_post->post_excerpt;
       $excerpt = apply_filters('the_content', $excerpt);
       $excerpt = str_replace(']]>', ']]>', $excerpt);
       echo $excerpt . "
    
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路