简体   繁体   English

发布网址不在锚href标签中

[英]Post url is not coming in anchor href tag

My code is 我的代码是

$args=array(
'post_type' => "product",
'post_status' => 'publish',
'taxonomy'   => 'products_category',
'order' =>'ASC',
'number'     => '',
'hide_empty'  => 0 );
 $my_query = new WP_Query( $args );
echo '<ul class="product_category">';
    if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); 
            echo '<li>';
            echo '<a href='. the_permalink() .'>';
            echo the_title();
            echo '</a></li>';
        endwhile;
    }
 echo '</ul>';wp_reset_query();

I want to show posts of product post type. 我想显示产品帖子类型的帖子。 Posts are coming correctly, but link of post not coming inside a href tag. 帖子正确发送,但帖子链接不在href标记内。

Instead of using the_permalink() use get_permalink(); 不用get_permalink()来使用the_permalink();

$args=array(
'post_type' => "product",
'post_status' => 'publish',
'taxonomy'   => 'products_category',
'order' =>'ASC',
'number'     => '',
'hide_empty'  => 0 );
 $my_query = new WP_Query( $args );
echo '<ul class="product_category">';
    if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); 
            echo '<li>';
            echo '<a href='. get_permalink() .'>';
            the_title();
            echo '</a></li>';
        endwhile;
    }
 echo '</ul>';wp_reset_query();

使用get_permalink()而不是the_permalink() ,如果仍然存在问题,请尝试$my_query->get_permalink()

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

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