snipt

Ctrl+h for KB shortcuts

PHP

WordPress home menu

<?php wp_page_menu('sort_column=menu_order&show_home=1') ?>
https://snipt.net/embed/088f07c29ca5cbd750c2172f150bfc72/
/raw/088f07c29ca5cbd750c2172f150bfc72/
088f07c29ca5cbd750c2172f150bfc72
php
PHP
1
2019-08-23T03:23:55
True
False
False
/api/public/snipt/6240/
wordpress-home-menu
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</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="nx">wp_page_menu</span><span class="p">(</span><span class="s1">&#39;sort_column=menu_order&amp;show_home=1&#39;</span><span class="p">)</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
wordpress

PHP

Get category ID

1
2
3
<?php
get_cat_id('categoryName');
?>
https://snipt.net/embed/4bae725fe98a59bd68f069b8a324be88/
/raw/4bae725fe98a59bd68f069b8a324be88/
4bae725fe98a59bd68f069b8a324be88
php
PHP
3
2019-08-22T08:49:08
True
False
False
/api/public/snipt/5608/
get-category-id
<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></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><span id="L-2"><a name="L-2"></a><span class="nx">get_cat_id</span><span class="p">(</span><span class="s1">&#39;categoryName&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
get_cat_id, wordpress

PHP

Get $post_category_id

1
2
3
4
5
<?php
foreach(get_the_category() as $category) {
  $post_category_id = $category->cat_ID;
}
?>
https://snipt.net/embed/70f7f3e375a3cbb30c78b8dc19cd6ed0/
/raw/70f7f3e375a3cbb30c78b8dc19cd6ed0/
70f7f3e375a3cbb30c78b8dc19cd6ed0
php
PHP
5
2019-08-22T08:49:29
True
False
False
/api/public/snipt/5607/
get-post_category_id
<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></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><span id="L-2"><a name="L-2"></a><span class="k">foreach</span><span class="p">(</span><span class="nx">get_the_category</span><span class="p">()</span> <span class="k">as</span> <span class="nv">$category</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$post_category_id</span> <span class="o">=</span> <span class="nv">$category</span><span class="o">-&gt;</span><span class="na">cat_ID</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
post_category_id, wordpress

PHP

get_page_id

1
2
3
4
5
6
7
<?php
function get_page_id($page_name){
	global $wpdb;
	$page_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."' AND post_status = 'publish' AND post_type = 'page'");
	return $page_name;
}
?>
https://snipt.net/embed/faafcefaf8000a0f4ed0e2b483d75ce8/
/raw/faafcefaf8000a0f4ed0e2b483d75ce8/
faafcefaf8000a0f4ed0e2b483d75ce8
php
PHP
7
2019-08-22T08:50:56
True
False
False
/api/public/snipt/5603/
get_page_id
<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></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><span id="L-2"><a name="L-2"></a><span class="k">function</span> <span class="nf">get_page_id</span><span class="p">(</span><span class="nv">$page_name</span><span class="p">){</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">global</span> <span class="nv">$wpdb</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$page_name</span> <span class="o">=</span> <span class="nv">$wpdb</span><span class="o">-&gt;</span><span class="na">get_var</span><span class="p">(</span><span class="s2">&quot;SELECT ID FROM </span><span class="si">$wpdb-&gt;posts</span><span class="s2"> WHERE post_name = &#39;&quot;</span><span class="o">.</span><span class="nv">$page_name</span><span class="o">.</span><span class="s2">&quot;&#39; AND post_status = &#39;publish&#39; AND post_type = &#39;page&#39;&quot;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">return</span> <span class="nv">$page_name</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span><span id="L-7"><a name="L-7"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
get_page_id, wordpress

CSS

destacar comentarios de users "autentidficados"

1
2
3
4
5
6
7
li.bypostauthor {
    /* CSS styles for author comments */
}

li.byuser {
    /* CSS styles for registered users comments */
}
https://snipt.net/embed/211d1929228fdcfe3804ee247766182e/
/raw/211d1929228fdcfe3804ee247766182e/
211d1929228fdcfe3804ee247766182e
css
CSS
8
2019-08-22T15:22:08
True
False
False
/api/public/snipt/5059/
destacar-comentarios-de-users-autentidficados
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nt">li</span><span class="nc">.bypostauthor</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="c">/* CSS styles for author comments */</span> </span><span id="L-3"><a name="L-3"></a><span class="p">}</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="nt">li</span><span class="nc">.byuser</span> <span class="p">{</span> </span><span id="L-6"><a name="L-6"></a> <span class="c">/* CSS styles for registered users comments */</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
commments, css, wordpress

PHP

Allowed Tags

Allowed tags: <?php echo allowed_tags(); ?>
https://snipt.net/embed/44e91f5e2d0f117bcd761072d2c26073/
/raw/44e91f5e2d0f117bcd761072d2c26073/
44e91f5e2d0f117bcd761072d2c26073
php
PHP
1
2019-08-22T08:52:53
True
False
False
/api/public/snipt/5039/
allowed-tags
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">Allowed tags: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nx">allowed_tags</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
"user code", tags, wordpress