【问题标题】:Post url is not coming in anchor href tag帖子网址没有出现在锚href标签中
【发布时间】:2015-09-30 08:41:20
【问题描述】:

我的代码是

$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();

我想显示产品帖子类型的帖子。帖子正确发送,但帖子链接未包含在 href 标记内。

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    不要使用 the_permalink() 而是使用 get_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();
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多