2015-12-02 96 views
2

我有一个帖子显示来自其他帖子的标题,而不是只有它唯一的帖子的问题。其他部分是好的,即没有其他重复,只是标题。WordPress循环显示其他帖子标题而不只是一个

我的代码生成的内容:

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 + 1。例如:

  • 工作后1
  • 作业后1Job柱2
  • 作业后1作业后2Job邮政3 ..

当它应该是:

  • 招聘职位1
  • 招聘职位2
  • 工作后3

回答

2

那么它看起来像你的连接字符串,即去除斑点的=前

$output_title .= get_the_title(); 

应该

$output_title = get_the_title(); 
1

的问题是由您使用造成的$output_title .= get_the_title().=应改为=

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