Echo Wordpress帖子ID在连接中

时间:2015-11-11 16:10:31

标签: php wordpress concatenation

请查看下面的代码块:

<?php print '
        <div class="present">
            <a href="LINKHERE">'.$content.'</a>
        </div>
'; ?>

我在 LINK HERE 的地方,我试图将以下代码包含href路径,后跟当前wordpress帖子ID的PHP回显。

('/go/'); echo the_ID();

我的问题是如何在连接中添加'echo'。

我尝试过以下操作但收到解析错误:

<a href="/go/'.echo the_ID();.'">'.$content.'</a>

2 个答案:

答案 0 :(得分:0)

                    print '
                        <article'.$article_class.' onclick=””>
                            <div id="on-'.$day.'" class="box" >
<img src="">
                            </div>
                            <div class="present">
                                <a href="/go/'.the_ID().'">'.$content.'</a>
                            </div>
                        </article>
                    ';

问题是我在the_ID()之后有一个中断,这显然导致了解析错误

答案 1 :(得分:0)

真正的答案是你应该永远 echoprint the_ID()(已经displays the post ID)。相反,在连接字符串时,您应该使用get_the_ID()return ID。

例如:

echo 'The ID is: ' . get_the_ID() . '. Some other string.';