Wordpress在页面上使用Allow PHP in Posts and Pages插件进行查询
它做了我希望它做的事情,在页面上的一列中显示特定类别的帖子。现在它只是标题,但我想链接该标题和永久链接部分不起作用,或者更确切地说是hrefWordpress在页面上使用Allow PHP in Posts and Pages插件进行查询,php,wordpress,Php,Wordpress,它做了我希望它做的事情,在页面上的一列中显示特定类别的帖子。现在它只是标题,但我想链接该标题和永久链接部分不起作用,或者更确切地说是href [php] // The Query $the_query = new WP_Query( 'cat=3' ); // The Loop if ( $the_query->have_posts() ) { echo '<ul style="list-style:none;">'; while ( $the_query-&
[php]
// The Query
$the_query = new WP_Query( 'cat=3' );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul style="list-style:none;">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . '<a href="the_permalink();">' . get_the_title() . '[/a]'. '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
[/php]
它链接到subdomain.domain.com/site/the_permalink;而是为该帖子拉永久链接并链接到它。永久链接;返回以回显您的链接。 您只需要返回字符串。为此,您可以使用get_permalink$post->ID;
因为permalink函数在echo函数中。当您输入以HTML开头的a标记时,如果关闭它,您将更改为BBCode。Fatih是正确的,您需要使用函数。因为您在循环中,所以不需要指定参数$post->ID 另外,您需要切换回PHP,这是您的主要问题,就像使用get_the_title函数一样。代码括号中存在多个语法问题 这条线应该是这样的:
echo '<li><a href="'.get_permalink().'">' . get_the_title() . '</a></li>';
了解echo和return之间的区别,不仅仅是PHP函数