snipt

Ctrl+h for KB shortcuts

PHP

WP : exclude certain categories from search engines

1
2
3
4
5
<?php
// code to insert inside your head section in header.php template file
	if(in_category('xxx') || in_category('xxx')) : ?>
	<meta name="robots" content="noindex" />
	<?php endif; ?>
https://snipt.net/embed/058afbf496497cd1645ca38c12f5f5ad/
/raw/058afbf496497cd1645ca38c12f5f5ad/
058afbf496497cd1645ca38c12f5f5ad
php
PHP
5
2019-08-21T07:20:14
True
False
False
Dec 17, 2012 at 04:04 PM
/api/public/snipt/52005/
wp-exclude-certain-categories-from-search-engines
<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="c1">// code to insert inside your head section in header.php template file</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">if</span><span class="p">(</span><span class="nx">in_category</span><span class="p">(</span><span class="s1">&#39;xxx&#39;</span><span class="p">)</span> <span class="o">||</span> <span class="nx">in_category</span><span class="p">(</span><span class="s1">&#39;xxx&#39;</span><span class="p">))</span> <span class="o">:</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-4"><a name="L-4"></a><span class="x"> &lt;meta name=&quot;robots&quot; content=&quot;noindex&quot; /&gt;</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> </span><span class="cp">&lt;?php</span> <span class="k">endif</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
Wordpress

PHP

List Registered Sidebar ids Wordpress

1
2
3
4
5
6
7
 <?php 
global $wp_registered_sidebars;
foreach ($wp_registered_sidebars as $a_sidebar)
	{ 
		echo $a_sidebar['id']."<br />"; 
    }
?>
https://snipt.net/embed/659945cfa276d320b1e3c5e0b86b689b/
/raw/659945cfa276d320b1e3c5e0b86b689b/
659945cfa276d320b1e3c5e0b86b689b
php
PHP
7
2019-08-24T07:54:12
True
False
False
Oct 17, 2012 at 06:12 PM
/api/public/snipt/48725/
list-registered-sidebar-ids-wordpress
<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="x"> </span><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="k">global</span> <span class="nv">$wp_registered_sidebars</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="k">foreach</span> <span class="p">(</span><span class="nv">$wp_registered_sidebars</span> <span class="k">as</span> <span class="nv">$a_sidebar</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="k">echo</span> <span class="nv">$a_sidebar</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span><span class="o">.</span><span class="s2">&quot;&lt;br /&gt;&quot;</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>
Wordpress

PHP

Basic Wordpress Loop

1
2
3
4
5
6
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>


<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
https://snipt.net/embed/99701b047aa99f02d82e462612f20cd2/
/raw/99701b047aa99f02d82e462612f20cd2/
99701b047aa99f02d82e462612f20cd2
php
PHP
7
2019-08-24T07:55:41
True
False
False
/api/public/snipt/45776/
basic-wordpress-loop
<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></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="k">if</span> <span class="p">(</span> <span class="nx">have_posts</span><span class="p">()</span> <span class="p">)</span> <span class="o">:</span> <span class="k">while</span> <span class="p">(</span> <span class="nx">have_posts</span><span class="p">()</span> <span class="p">)</span> <span class="o">:</span> <span class="nx">the_post</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><span id="L-4"><a name="L-4"></a><span class="cp">&lt;?php</span> <span class="k">endwhile</span><span class="p">;</span> <span class="k">else</span><span class="o">:</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-5"><a name="L-5"></a><span class="x">&lt;p&gt;</span><span class="cp">&lt;?php</span> <span class="nx">_e</span><span class="p">(</span><span class="s1">&#39;Sorry, no posts matched your criteria.&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x">&lt;/p&gt;</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">&lt;?php</span> <span class="k">endif</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
Loop, Wordpress

PHP

Control Wordpress posts per page

1
2
3
4
5
6
    <?php
$page_num = $paged;
if ($pagenum='') $pagenum =1;
query_posts('showposts=20&paged='.$page_num); ?>
         
    
https://snipt.net/embed/d1230e43e996fccde11a5dfb423aed02/
/raw/d1230e43e996fccde11a5dfb423aed02/
d1230e43e996fccde11a5dfb423aed02
php
PHP
6
2019-08-24T07:56:08
True
False
False
Aug 16, 2012 at 09:09 AM
/api/public/snipt/45775/
control-wordpress-posts-per-page
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x"> </span><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$page_num</span> <span class="o">=</span> <span class="nv">$paged</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="k">if</span> <span class="p">(</span><span class="nv">$pagenum</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">)</span> <span class="nv">$pagenum</span> <span class="o">=</span><span class="mi">1</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="nx">query_posts</span><span class="p">(</span><span class="s1">&#39;showposts=20&amp;paged=&#39;</span><span class="o">.</span><span class="nv">$page_num</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span><span id="L-5"><a name="L-5"></a><span class="x"> </span> </span><span id="L-6"><a name="L-6"></a><span class="x"> </span> </span></pre></div> </td></tr></table>
Wordpress, loop, php, posts