[英]Wordpress how to use <a href> in wp_query?
我有一個wp_query
列出子類別的文章標題和摘錄。 我希望標題鏈接到其相應的帖子,但是無法在以下代碼中弄清楚如何使a href正常工作。 從以下代碼生成的鏈接是/category/sub-category/the_permalink()
。 有什么建議嗎?
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'posts_per_page' => 10, 'order'=> 'ASC', 'orderby' => 'title', 'category_name' => 'diet-tips', 'paged' => $paged,'post_type' => 'post' );
$postslist = new WP_Query( $args );
if ( $postslist->have_posts() ) :
while ( $postslist->have_posts() ) :
$postslist->the_post();
echo "<div style='border:1px groove gray; margin-bottom:5px;'><h3 class='btposth'><a href='the_permalink()'>";
the_title();
echo "</a></h3><div class='btpostdiv'>";
the_excerpt();
echo "</div></div>";
"<br />";
endwhile;
next_posts_link( 'Older Entries', $postslist->max_num_pages );
previous_posts_link( 'Next Entries »' );
wp_reset_postdata();
endif;
感謝大家的幫助,產生我想要的結果的代碼是這樣的:
echo "<div style='border:1px groove gray; margin-bottom:5px;'><h3 class='btposth'><a href='" . get_the_permalink() . "'>";
the_title();
echo "</a>
您試圖將單詞the_permalink()
打印為文本而不是函數。 嘗試這個:
echo "<div style='border:1px groove gray; margin-bottom:5px;'><h3 class='btposth'><a href='".the_permalink()."'>";
the_title();
echo "</a></h3><div class='btpostdiv'>";
較短的版本:
echo "<div style='border:1px groove gray; margin-bottom:5px;'><h3 class='btposth'><a href='".the_permalink()."'>".the_title()."</a></h3><div class='btpostdiv'>";
編輯:沒有回顯功能:
<div style="border:1px groove gray; margin-bottom:5px;">
<h3 class="btposth"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<div class='btpostdiv'>
echo '<a href='".the_permalink()."'>';
Somelinks
echo '</a>';
嘗試這個
echo "<div style='border:1px groove gray; margin-bottom:5px;'><h3 class='btposth'><a href=".the_permalink().">".the_title()."</a></h3><div class='btpostdiv'>".the_excerpt()."</div></div>";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.