如何将帖子链接到其目录

问题描述 投票:0回答:1

你好。当我的帖子被点击时,我想添加一个链接。链接必须转到帖子的类别。我已经走了这么远。但是现在我卡住了。谁能告诉我我该怎么做? thkx

'portriats','posts_per_page'=> 1); ?>
       <?php $qry = new WP_Query($args ); ?>
       <?php if ( $qry->have_posts() ) : ?>



  <?php while ( $qry->have_posts() ) : $qry->the_post(); $postcat = get_the_category( $post->ID );?>

                                                <div class="hometile">
                                                <a href="<?php get_category_link( $postcat) ?>"> ==> **I need to get the category of the post. and then let php print the link of the categorey  in the href**

            <?php the_post_thumbnail(); ?></a>


                                                </div>

                                        <?php endwhile; ?>
                                    <?php endif; ?>
wordpress post hyperlink categories
1个回答
0
投票

它将显示带有链接的帖子的主要类别

<?php $qry = new WP_Query($args ); ?>
<?php if ( $qry->have_posts() ) : ?>

  <?php while ( $qry->have_posts() ) : $qry->the_post(); $postcat = get_the_category();?>
 <div class="hometile">
  <a href="<?php echo get_category_link( $postcat[0]->term_id ); ?>">
   <?php echo $postcat[0]->name; ?>
   <?php the_post_thumbnail(); ?>
  </a>

 </div>

 <?php endwhile; ?>
<?php endif; ?>
© www.soinside.com 2019 - 2024. All rights reserved.