snipt

Ctrl+h for KB shortcuts

PHP

wordpress获取当前页面里分类的相关信息

1
2
3
4
5
6
7
8
<?php $category = get_the_category();echo $category[0]->category_nicename;?>

//cat_ID - 分类ID
//cat_name - 分类名
//category_nicename - 别名
//category_description - 分类描述
//category_parent - 父分类ID 
//category_count - 包涵文章数量
https://snipt.net/embed/b17d648fa583f25dd6fc2b48164f7275/
/raw/b17d648fa583f25dd6fc2b48164f7275/
b17d648fa583f25dd6fc2b48164f7275
php
PHP
8
2016-12-25T13:55:32
True
False
True
Dec 12, 2013 at 10:44 PM
/api/public/snipt/100237/
wordpress-11
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="nv">$category</span> <span class="o">=</span> <span class="nx">get_the_category</span><span class="p">();</span><span class="k">echo</span> <span class="nv">$category</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-&gt;</span><span class="na">category_nicename</span><span class="p">;</span><span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="x">//cat_ID - 分类ID</span> </span><span id="L-4"><a name="L-4"></a><span class="x">//cat_name - 分类名</span> </span><span id="L-5"><a name="L-5"></a><span class="x">//category_nicename - 别名</span> </span><span id="L-6"><a name="L-6"></a><span class="x">//category_description - 分类描述</span> </span><span id="L-7"><a name="L-7"></a><span class="x">//category_parent - 父分类ID </span> </span><span id="L-8"><a name="L-8"></a><span class="x">//category_count - 包涵文章数量</span> </span></pre></div> </td></tr></table>
category, wordpress