【问题标题】:WordPress loop displaying other post titles instead of just oneWordPress 循环显示其他帖子标题,而不仅仅是一个
【发布时间】:2015-12-02 22:00:08
【问题描述】:

我的帖子显示其他帖子的标题时遇到问题,而不仅仅是它独有的单个帖子。其他部分很好,即没有其他重复,只是标题。

我生成内容的代码:

get_header();

$the_query = new WP_Query( 'category_name=careers&showposts=5' );
while ( $the_query->have_posts() ) :
    $output = "";
    $the_query->the_post();
    $output_title .= get_the_title();
    $output_content .= get_the_content();
    $output_type = get_field('job_type');
    $output_salary = get_field('job_salary');
    $output_intro = get_field('job_intro');

    $careers.= '
        <div class="careers">
            <h3>'.$output_title.'</h3>
            <p class="type">'.$output_type.'</p>
            <p class="salary">'.$output_salary.'</p>
            <p>'.$output_intro.'</p>
    </div>
    ';
endwhile;
wp_reset_postdata();

所以发生的情况是,最新的帖子显示了一个标题,这很好,但是第二个帖子显示了它的标题 + 最新,第三个职位显示了它的标题 +2+1st。例如:

  • 招聘帖1
  • 职位发布1职位发布2
  • 职位 1 职位 2 职位 3..

什么时候应该:

  • 招聘帖1
  • 招聘帖2
  • 职位发布 3

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    看来您正在连接字符串,即删除 = 前面的点

    $output_title .= get_the_title();
    

    应该是

    $output_title = get_the_title();
    

    【讨论】:

      【解决方案2】:

      问题是由您使用$output_title .= get_the_title() 引起的。 .= 应更改为 =

      while ( $the_query->have_posts() ) :
          $output = "";
          $the_query->the_post();
          $output_title = get_the_title(); // Change this line
      endwhile;
      

      【讨论】:

        猜你喜欢
        • 2018-09-02
        • 2023-03-10
        • 1970-01-01
        • 2019-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-21
        • 2015-02-16
        相关资源
        最近更新 更多