Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

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/
https://snipt.net/raw/b17d648fa583f25dd6fc2b48164f7275/
b17d648fa583f25dd6fc2b48164f7275
php
PHP
8
2016-12-02T18:48:43
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

PHP

Imprimir imagen de una taxonomia/categoria con "Taxonomy Images" Plugin

1
2
3
4
<?php $categories = apply_filters( 'taxonomy-images-get-terms', '', 
array( 'term_args' => '&include=/*IDCATEGORIA*/orderby=count&hide_empty=0') ); 
$category_image = wp_get_attachment_image_src( $categories[0]->image_id, 'medium' ); 
echo '<img src="' . $category_image[0] . '" alt="" />'; ?>
https://snipt.net/embed/77777e9d1a3532e484e2807a7b863c31/
https://snipt.net/raw/77777e9d1a3532e484e2807a7b863c31/
77777e9d1a3532e484e2807a7b863c31
php
PHP
5
2016-12-08T03:29:19
True
False
False
Dec 07, 2012 at 02:57 PM
/api/public/snipt/51425/
imprimir-imagen-de-una-taxonomiacategoria-con-taxonomy-images-plugin
<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></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">$categories</span> <span class="o">=</span> <span class="nx">apply_filters</span><span class="p">(</span> <span class="s1">&#39;taxonomy-images-get-terms&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> </span><span id="L-2"><a name="L-2"></a><span class="k">array</span><span class="p">(</span> <span class="s1">&#39;term_args&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;&amp;include=/*IDCATEGORIA*/orderby=count&amp;hide_empty=0&#39;</span><span class="p">)</span> <span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$category_image</span> <span class="o">=</span> <span class="nx">wp_get_attachment_image_src</span><span class="p">(</span> <span class="nv">$categories</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-&gt;</span><span class="na">image_id</span><span class="p">,</span> <span class="s1">&#39;medium&#39;</span> <span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="k">echo</span> <span class="s1">&#39;&lt;img src=&quot;&#39;</span> <span class="o">.</span> <span class="nv">$category_image</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">.</span> <span class="s1">&#39;&quot; alt=&quot;&quot; /&gt;&#39;</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
category, plugin, taxonomy, wordpress
Copyrighted, illegal, or inappropriate content? Email [email protected].