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

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

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

推荐阅读:
HPZ800 Server Does Not Support Hard Drives Larger Than 2TB  Fresno Blogger Changing The Vegan Blogging Scene  Russian ‘Pokemon Go’ Blogger Goes On Trial  Starting a Blog? 5 Topics People Care About in 2017  6 Strategies To Grow Your Facebook Page  5 Sure Shot Content Marketing Trends to Follow  7 Ways for Your Underdog Blog to Beat the Competition  Darkstore Aims to be Less Invasive Alternative to Tech Giants ac  5 Free Blogging Apps You Need On Your IPhone Right Now  The Exact Amount that You Must Spend on a Great Blog Is… 
评论列表
添加评论