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

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

对于杂志(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

推荐阅读:
The Difference Between Sum of Squares and Square of the Sum  Number of Steps to Reduce a Number in Binary Representation to O  Recursive Depth First Search Algorithm to Compute the Diameter o  Find the largest palindrome From the product of two 3-digit numb  What is the largest prime factor of the number 600851475143 ?  Can we Construct K Palindrome Strings?  Sum of Even Fibonacci Numbers  Sum of Multiples of 3 and 5  How to Design Underground System using Several Hash Maps?  How to Remove Zero Sum Consecutive Nodes from Linked List using  
评论列表
添加评论