Php 删除单个页面中的标题链接

Php 删除单个页面中的标题链接,php,wordpress,Php,Wordpress,这就是我如何称呼这篇文章的标题: <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 我的主题中没有single.php: <?php if (is_singular()) {<h2><?php the_title(); ?></h2>}; else {<h2>

这就是我如何称呼这篇文章的标题:

<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

我的主题中没有single.php:

<?php
    if (is_singular()) {<h2><?php the_title(); ?></h2>};
    else {<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>}
?>
};
else{}
?>

但是上面的代码不起作用,知道吗?

这是一个语法错误。你可能想要这样的东西

<?php if (is_singular()) { ?>
    <h2><?php the_title(); ?></h2>
<?php } else { ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php } ?>

这是一个语法错误。你可能想要这样的东西

<?php if (is_singular()) { ?>
    <h2><?php the_title(); ?></h2>
<?php } else { ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php } ?>

在这种情况下,一个很好的做法是将所有代码放在一行,而不是将所有代码都放在一行中。这使得更容易看到语法错误,例如忘记使用“?>”,就像您在if语句的开始括号后所做的那样

<?php
if (is_singular()) 
{ ?>
    <h2><?php the_title(); ?></h2>
<?php }
else 
{ ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php }
?>

尽管在您的情况下,最好不要一直像那样中断编码,而只是使用echo来写行

<?php
if (is_singular()) 
{ 
    echo '<h2>'. the_title() .'</h2>';
}
else 
{
    echo '<h2><a href="'. the_permalink() .'">'. the_title() .'</a></h2>';
}
?>

在这种情况下,一个很好的做法是将所有代码放在一行,而不是将所有代码都放在一行中。这使得更容易看到语法错误,例如忘记使用“?>”,就像您在if语句的开始括号后所做的那样

<?php
if (is_singular()) 
{ ?>
    <h2><?php the_title(); ?></h2>
<?php }
else 
{ ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php }
?>

尽管在您的情况下,最好不要一直像那样中断编码,而只是使用echo来写行

<?php
if (is_singular()) 
{ 
    echo '<h2>'. the_title() .'</h2>';
}
else 
{
    echo '<h2><a href="'. the_permalink() .'">'. the_title() .'</a></h2>';
}
?>


我不会对此投反对票,但回声的建议非常主观。我觉得维护和编辑很烦人。分离html和php对我来说更清楚(同样是主观的),你是对的,但对我来说,对于初学者来说,这是一件显而易见的事情。它至少向他展示了两种方法,可以让它在不崩溃的情况下工作。字符串连接似乎更难处理。
title()
不返回字符串。它发出某种回声。因此,
echo''。_title()。'将回显
标题
。与下面的
相同。我不会对此投反对票,但回声建议非常主观。我觉得维护和编辑很烦人。分离html和php对我来说更清楚(同样是主观的),你是对的,但对我来说,对于初学者来说,这是一件显而易见的事情。它至少向他展示了两种方法,可以让它在不崩溃的情况下工作。字符串连接似乎更难处理。
title()
不返回字符串。它发出某种回声。因此,
echo''。_title()。'将回显
标题
。与下面的
相同。