wordpress主题制作时调用分类链接的方法

  • 时间:2020-05-22 15:47:15
  • 分类:网络文摘
  • 阅读:154 次

对于杂志(CMS)类的wordpress主题而言,通常以多分类列表形式来展现网站首页内容,制作时需要在wordpress主题合适位置添加各分类归档页面链接的按钮,下面介绍两段代码,分别通过分类别名、分类ID两种wordpress技巧帮你快速实现分类链接的获取。

代码一:通过分类别名调用wordpress分类链接。

  1. <?php
  2. $cat=get_category_by_slug('wordpress');
  3. $cat_links=get_category_link($cat->term_id);
  4. ?>
  5. <a href="http://uuxn.com/wordpress-theme-call-category-links/<?php echo $cat_links; ?>" title="<?php echo $cat->name; ?>">更多</a>

代码二:通过分类 ID 调用Wordpress分类链接。

  1. <?php
  2. $cat=get_term_by('id', 12, 'category');
  3. $cat_links=get_category_link($cat->term_id);
  4. ?>
  5. <a href="http://uuxn.com/wordpress-theme-call-category-links/<?php echo $cat_links; ?>" title="<?php echo $cat->name; ?>">更多</a>

代码参考:

http://codex.wordpress.org/Function_Reference/get_category_by_slug
http://codex.wordpress.org/Function_Reference/get_term_by

推荐阅读:
Five Tips to Lower Your Tax Bill in 2020  Bruteforce Algorithm to Compute the Maxmium Powerful Digit Sum u  4 Frequently Discussed SEO Myths Exposed  3 Reasons Why Graphic Designers Need to Self-Promote through Ins  How to Split a String in C++?  The Best Instagram Feed WordPress Plugins to Use  Trie Class Data Structure in Python  How to Monitor the CPU Temperature of Raspberry PI using Python   Listen to what an SEO expert has to say about its benefits  Depth First Search Algorithm to Compute the Smallest String Star 
评论列表
添加评论