WordPress循环显示其他帖子标题而不是一个

问题描述 投票:2回答:2

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

我的代码生成内容:

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
  • Job Post 1Job post 2
  • Job Post 1 Job Post 2Job Post 3 ..

它应该是:

  • 职位1
  • 职位2
  • 职位3
php wordpress
2个回答
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;
© www.soinside.com 2019 - 2024. All rights reserved.