Php 我的WP循环脚本中的Ghost post_标题

Php 我的WP循环脚本中的Ghost post_标题,php,wordpress,variables,while-loop,echo,Php,Wordpress,Variables,While Loop,Echo,下面的代码在显示带有超链接的蓝色标题之前以黑色文本显示标题 我只希望链接出现 if ( $query2->have_posts() ) { // The 2nd Loop while ( $query2->have_posts() ) { $query2->the_post(); if ($post->ID == $do_not_duplicate) continue;

下面的代码在显示带有超链接的蓝色标题之前以黑色文本显示标题

我只希望链接出现

if ( $query2->have_posts() ) {
    // The 2nd Loop
    while ( $query2->have_posts() ) {
        $query2->the_post();
                 if ($post->ID == $do_not_duplicate)
                continue;
                $permalink = get_the_permalink($query2->post->ID);
                $ID = $post->ID;
                $titleAtribute = the_title_attribute();
                $title = get_the_title();
        echo '<h2 id="post-' .$ID.' ">
                <a href="'.$permalink.'" rel="bookmark" title="Permanent Link to '.$permalink.' ">
                   '.$title.'</a></h2>';
    }

    // Restore original Post Data
    wp_reset_postdata();
}
if($query2->have_posts()){
//第二圈
而($query2->have_posts()){
$query2->the_post();
如果($post->ID=$do\U not\U duplicate)
继续;
$permalink=获取\u permalink($query2->post->ID);
$ID=$post->ID;
$titleAttribute=标题属性();
$title=获取标题();
回声'
';
}
//恢复原始Post数据
wp_reset_postdata();
}
例如,在我的网站:,以下文本以黑色显示在具有相同文本的链接上方:

-Martin Davídek ml.:“Fanoušci jsou vždy to,co vásžene kupředu”-


这是从哪里来的?我需要做些什么来阻止它出现?

问题在于
标题属性()
。这是直接显示值而不是返回值

函数接受$args中的
echo
,以指定是显示还是返回值。默认值为true(显示),因此传递false以返回值,例如:

$titleAtribute = the_title_attribute('echo=0');

好的,如果我不打算显示它,为什么我要用代码来显示它呢?:O感谢您的建议您不想立即显示它-现在就是这样。您要做的是获取值并将其保存在名为
$titleAttribute
的变量中,以便您可以随时使用它来显示它。就像
$tit>一样le=获取_title();
-此时您不会在屏幕上显示它,而是将其保存到
$title
变量中,然后在创建链接时在下一行中使用
$title
。(您在包含的代码中根本不使用
$titleAttribute
,但可能在其他地方使用它)。