cod*_*dek 0 php ajax wordpress
我正在尝试使用常规wp_query列出帖子标题,只是为了将项目的href添加到永久链接,这是我正在使用的代码:
<?php $the_query = new WP_Query( 'post_type=artworks_post' );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<a rel="' .the_permalink(). '" href="' .the_permalink. ' ">';
the_title();
echo '</a>';
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
Run Code Online (Sandbox Code Playgroud)
问题是代码不起作用,它只返回带有"永久链接"一词的href,但没有链接本身.
我在这里做错了什么?
尝试使用get_permalink而不是the_permalink.函数the_permalink正在打印永久链接本身(http://codex.wordpress.org/Function_Reference/the_permalink),但函数get_permalink返回永久链接字符串(http://codex.wordpress.org/Function_Reference/get_permalink).
无论如何只是一个建议,使用printf而不是echo.如,
<?php $the_query = new WP_Query( 'post_type=artworks_post' );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<a rel="' .the_permalink(). '" href="' .the_permalink. ' ">';
the_title();
echo '</a>';
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
Run Code Online (Sandbox Code Playgroud)
根据要求,我使用echo而不是printf添加示例
<?php
$the_query = new WP_Query( 'post_type=artworks_post' );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<a rel="' .get_permalink(). '" href="' .get_permalink(). ' ">';
the_title();
echo '</a>';
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6961 次 |
| 最近记录: |