简体   繁体   English

快速PHP回声帮助

[英]Quick PHP echo help

What is wrong with this? 这有什么问题?

echo '<a title="Last Chance" href="'.the_permalink().'" class="status open">Last Chance</a>';

As it's putting the the_permalink() before the <a instead of inside it. 因为它将the_permalink()放在<a之前而不是放在它内部。

Wordpress often echo 's the content out of the function instead of returning it. Wordpress经常echo函数的内容而不是返回它。

Use get_permalink() instead. 请改用get_permalink()

echo '<a title="Last Chance" href="'.get_permalink().'" class="status open">Last Chance</a>';

http://codex.wordpress.org/Function_Reference/get_permalink http://codex.wordpress.org/Function_Reference/the_permalink http://codex.wordpress.org/Function_Reference/get_permalink http://codex.wordpress.org/Function_Reference/the_permalink

Actually it looks good to me (but see my edit comment). 实际上它看起来不错(但请参阅我的编辑评论)。

Better is to embed PHP into HTML: 更好的是将PHP嵌入到HTML中:

<a title="Last Chance" href="<?php the_permalink(); ?>" class="status open">
   Last Chance
</a>

Edit: As @Marwelln found out , the_permalink() is already echoing data. 编辑: 正如@Marwelln发现的那样the_permalink()已经在回显数据。 Still, this is a better solution than echoing the HTML. 不过,这是一个比回显HTML更好的解决方案。

I guess you have echo "abc" in the the_permalink function. 我猜你在the_permalink函数中有echo "abc" In order for this to work as you wish, you have to return "abc" instead of using echo . 为了使其按您的意愿工作,您必须return "abc"而不是使用echo

Use it like this (not inside echo ) 像这样使用它(不在内部回声)

<a title="Last Chance" href=" <?php the_permalink() ?> " class="status open">Last Chance</a>

See http://codex.wordpress.org/Function_Reference/the_permalink for more details. 有关详细信息,请参阅http://codex.wordpress.org/Function_Reference/the_permalink

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM