<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WP Switch &#187; Wordpress Hacks</title>
	<atom:link href="http://wpswitch.com/tag/wordpress-hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpswitch.com</link>
	<description>Premium WordPress Themes and Design Blog</description>
	<lastBuildDate>Tue, 08 May 2012 13:34:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Monitor your Server in the WordPress Dashboard</title>
		<link>http://wpswitch.com/blog/monitor-your-server-in-the-wordpress-dashboard/</link>
		<comments>http://wpswitch.com/blog/monitor-your-server-in-the-wordpress-dashboard/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 14:47:58 +0000</pubDate>
		<dc:creator>WP Switch™</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://wpswitch.com/?p=3093</guid>
		<description><![CDATA[<p>Thanks for subscribing! <a href="http://wpswitch.com">WP Switch</a> - <a href="http://wpswitch.com">WP Switch - Premium WordPress Themes and Design Blog</a></p><p>This handy dashboard widget allows you to monitor your server directly on the WordPress dashboard. Simply copy the code below and paste in your functions.php file. For this to work you also must set the value of the $logfile variable at the start to the absolute server path of your log file. [php] function slt_PHPErrorsWidget() [...]</p>]]></description>
			<content:encoded><![CDATA[<p>Thanks for subscribing! <a href="http://wpswitch.com">WP Switch</a> - <a href="http://wpswitch.com">WP Switch - Premium WordPress Themes and Design Blog</a></p><p>This handy dashboard widget allows you to monitor your server directly on the WordPress dashboard.</p>
<p>Simply copy the code below and paste in your <em>functions.php</em> file. For this to work you also must set the value of the <em>$logfile</em> variable at the start to the absolute server path of your log file.<span id="more-3093"></span></p>
<p>[php]<br />
function slt_PHPErrorsWidget() {<br />
	$logfile = &#8216;/home/path/logs/php-errors.log&#8217;; // Enter the server path to your logs file here<br />
	$displayErrorsLimit = 100; // The maximum number of errors to display in the widget<br />
	$errorLengthLimit = 300; // The maximum number of characters to display for each error<br />
	$fileCleared = false;<br />
	$userCanClearLog = current_user_can( &#8216;manage_options&#8217; );<br />
	// Clear file?<br />
	if ( $userCanClearLog &amp;&amp; isset( $_GET[&quot;slt-php-errors&quot;] ) &amp;&amp; $_GET[&quot;slt-php-errors&quot;]==&quot;clear&quot; ) {<br />
		$handle = fopen( $logfile, &quot;w&quot; );<br />
		fclose( $handle );<br />
		$fileCleared = true;<br />
	}<br />
	// Read file<br />
	if ( file_exists( $logfile ) ) {<br />
		$errors = file( $logfile );<br />
		$errors = array_reverse( $errors );<br />
		if ( $fileCleared ) echo &#8216;&lt;p&gt;&lt;em&gt;File cleared.&lt;/em&gt;&lt;/p&gt;&#8217;;<br />
		if ( $errors ) {<br />
			echo &#8216;&lt;p&gt;&#8217;.count( $errors ).&#8217; error&#8217;;<br />
			if ( $errors != 1 ) echo &#8216;s&#8217;;<br />
			echo &#8216;.&#8217;;<br />
			if ( $userCanClearLog ) echo &#8216; [ &lt;b&gt;&lt;a href=&quot;'.get_bloginfo(&quot;url&quot;).'/wp-admin/?slt-php-errors=clear&quot; onclick=&quot;return confirm(\'Are you sure?\');&quot;&gt;CLEAR LOG FILE&lt;/a&gt;&lt;/b&gt; ]&#8216;;<br />
			echo &#8216;&lt;/p&gt;&#8217;;<br />
			echo &#8216;&lt;div id=&quot;slt-php-errors&quot; style=&quot;height:250px;overflow:scroll;padding:2px;background-color:#faf9f7;border:1px solid #ccc;&quot;&gt;&#8217;;<br />
			echo &#8216;&lt;ol style=&quot;padding:0;margin:0;&quot;&gt;&#8217;;<br />
			$i = 0;<br />
			foreach ( $errors as $error ) {<br />
				echo &#8216;&lt;li style=&quot;padding:2px 4px 6px;border-bottom:1px solid #ececec;&quot;&gt;&#8217;;<br />
				$errorOutput = preg_replace( &#8216;/\[([^\]]+)\]/&#8217;, &#8216;&lt;b&gt;[$1]&lt;/b&gt;&#8217;, $error, 1 );<br />
				if ( strlen( $errorOutput ) &gt; $errorLengthLimit ) {<br />
					echo substr( $errorOutput, 0, $errorLengthLimit ).&#8217; [...]&#8216;;<br />
				} else {<br />
					echo $errorOutput;<br />
				}<br />
				echo &#8216;&lt;/li&gt;&#8217;;<br />
				$i++;<br />
				if ( $i &gt; $displayErrorsLimit ) {<br />
					echo &#8216;&lt;li style=&quot;padding:2px;border-bottom:2px solid #ccc;&quot;&gt;&lt;em&gt;More than &#8216;.$displayErrorsLimit.&#8217; errors in log&#8230;&lt;/em&gt;&lt;/li&gt;&#8217;;<br />
					break;<br />
				}<br />
			}<br />
			echo &#8216;&lt;/ol&gt;&lt;/div&gt;&#8217;;<br />
		} else {<br />
			echo &#8216;&lt;p&gt;No errors currently logged.&lt;/p&gt;&#8217;;<br />
		}<br />
	} else {<br />
		echo &#8216;&lt;p&gt;&lt;em&gt;There was a problem reading the error log file.&lt;/em&gt;&lt;/p&gt;&#8217;;<br />
	}<br />
}</p>
<p>// Add widgets<br />
function slt_dashboardWidgets() {<br />
	wp_add_dashboard_widget( &#8216;slt-php-errors&#8217;, &#8216;PHP errors&#8217;, &#8216;slt_PHPErrorsWidget&#8217; );<br />
}<br />
add_action( &#8216;wp_dashboard_setup&#8217;, &#8216;slt_dashboardWidgets&#8217; );<br />
[/php]</p>
<p>If you are having some trouble in getting this to work more detailed instructions can be found from the source below.</p>
<p><span style="color: #ff00ff;">.via { <a href="http://sltaylor.co.uk/blog/wordpress-dashboard-widget-php-errors-log/">Steve Taylor</a> }</span></p>
]]></content:encoded>
			<wfw:commentRss>http://wpswitch.com/blog/monitor-your-server-in-the-wordpress-dashboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display WordPress Post Tags In A Dropdown Menu</title>
		<link>http://wpswitch.com/blog/display-wordpress-post-tags-in-a-dropdown-menu/</link>
		<comments>http://wpswitch.com/blog/display-wordpress-post-tags-in-a-dropdown-menu/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 02:50:30 +0000</pubDate>
		<dc:creator>WP Switch™</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://wpswitch.com/?p=1370</guid>
		<description><![CDATA[<p>Thanks for subscribing! <a href="http://wpswitch.com">WP Switch</a> - <a href="http://wpswitch.com">WP Switch - Premium WordPress Themes and Design Blog</a></p><p>We use this code here on WPswitch so you should to, or not..whatever! In your theme folder, paste the following code to the functions.php file. If you don&#8217;t have a functions.php file, create one. [php] &#60;?php function dropdown_tag_cloud( $args = &#8221; ) { $defaults = array( &#8216;smallest&#8217; =&#62; 8, &#8216;largest&#8217; =&#62; 22, &#8216;unit&#8217; =&#62; &#8216;pt&#8217;, [...]</p>]]></description>
			<content:encoded><![CDATA[<p>Thanks for subscribing! <a href="http://wpswitch.com">WP Switch</a> - <a href="http://wpswitch.com">WP Switch - Premium WordPress Themes and Design Blog</a></p><p><strong>We use this code here on WPswitch so you should to, or not..whatever! </strong></p>
<p>In your theme folder, paste the following code to the functions.php file. If you don&#8217;t have a functions.php file, create one.<span id="more-1370"></span></p>
<p>[php]<br />
&lt;?php<br />
function dropdown_tag_cloud( $args = &#8221; ) {<br />
	$defaults = array(<br />
		&#8216;smallest&#8217; =&gt; 8, &#8216;largest&#8217; =&gt; 22, &#8216;unit&#8217; =&gt; &#8216;pt&#8217;, &#8216;number&#8217; =&gt; 45,<br />
		&#8216;format&#8217; =&gt; &#8216;flat&#8217;, &#8216;orderby&#8217; =&gt; &#8216;name&#8217;, &#8216;order&#8217; =&gt; &#8216;ASC&#8217;,<br />
		&#8216;exclude&#8217; =&gt; &#8221;, &#8216;include&#8217; =&gt; &#8221;<br />
	);<br />
	$args = wp_parse_args( $args, $defaults );</p>
<p>	$tags = get_tags( array_merge($args, array(&#8216;orderby&#8217; =&gt; &#8216;count&#8217;, &#8216;order&#8217; =&gt; &#8216;DESC&#8217;)) ); // Always query top tags</p>
<p>	if ( empty($tags) )<br />
		return;</p>
<p>	$return = dropdown_generate_tag_cloud( $tags, $args ); // Here&#8217;s where those top tags get sorted according to $args<br />
	if ( is_wp_error( $return ) )<br />
		return false;<br />
	else<br />
		echo apply_filters( &#8216;dropdown_tag_cloud&#8217;, $return, $args );<br />
}</p>
<p>function dropdown_generate_tag_cloud( $tags, $args = &#8221; ) {<br />
	global $wp_rewrite;<br />
	$defaults = array(<br />
		&#8216;smallest&#8217; =&gt; 8, &#8216;largest&#8217; =&gt; 22, &#8216;unit&#8217; =&gt; &#8216;pt&#8217;, &#8216;number&#8217; =&gt; 45,<br />
		&#8216;format&#8217; =&gt; &#8216;flat&#8217;, &#8216;orderby&#8217; =&gt; &#8216;name&#8217;, &#8216;order&#8217; =&gt; &#8216;ASC&#8217;<br />
	);<br />
	$args = wp_parse_args( $args, $defaults );<br />
	extract($args);</p>
<p>	if ( !$tags )<br />
		return;<br />
	$counts = $tag_links = array();<br />
	foreach ( (array) $tags as $tag ) {<br />
		$counts[$tag-&gt;name] = $tag-&gt;count;<br />
		$tag_links[$tag-&gt;name] = get_tag_link( $tag-&gt;term_id );<br />
		if ( is_wp_error( $tag_links[$tag-&gt;name] ) )<br />
			return $tag_links[$tag-&gt;name];<br />
		$tag_ids[$tag-&gt;name] = $tag-&gt;term_id;<br />
	}</p>
<p>	$min_count = min($counts);<br />
	$spread = max($counts) &#8211; $min_count;<br />
	if ( $spread &lt;= 0 )<br />
		$spread = 1;<br />
	$font_spread = $largest &#8211; $smallest;<br />
	if ( $font_spread &lt;= 0 )<br />
		$font_spread = 1;<br />
	$font_step = $font_spread / $spread;</p>
<p>	// SQL cannot save you; this is a second (potentially different) sort on a subset of data.<br />
	if ( &#8216;name&#8217; == $orderby )<br />
		uksort($counts, &#8216;strnatcasecmp&#8217;);<br />
	else<br />
		asort($counts);</p>
<p>	if ( &#8216;DESC&#8217; == $order )<br />
		$counts = array_reverse( $counts, true );</p>
<p>	$a = array();</p>
<p>	$rel = ( is_object($wp_rewrite) &amp;&amp; $wp_rewrite-&gt;using_permalinks() ) ? &#8216; rel=&quot;tag&quot;&#8217; : &#8221;;</p>
<p>	foreach ( $counts as $tag =&gt; $count ) {<br />
		$tag_id = $tag_ids[$tag];<br />
		$tag_link = clean_url($tag_links[$tag]);<br />
		$tag = str_replace(&#8216; &#8216;, &#8216;&amp;nbsp;&#8217;, wp_specialchars( $tag ));<br />
		$a[] = &quot;\t&lt;option value=&#8217;$tag_link&#8217;&gt;$tag ($count)&lt;/option&gt;&quot;;<br />
	}</p>
<p>	switch ( $format ) :<br />
	case &#8216;array&#8217; :<br />
		$return =&amp; $a;<br />
		break;<br />
	case &#8216;list&#8217; :<br />
		$return = &quot;&lt;ul class=&#8217;wp-tag-cloud&#8217;&gt;\n\t&lt;li&gt;&quot;;<br />
		$return .= join(&quot;&lt;/li&gt;\n\t&lt;li&gt;&quot;, $a);<br />
		$return .= &quot;&lt;/li&gt;\n&lt;/ul&gt;\n&quot;;<br />
		break;<br />
	default :<br />
		$return = join(&quot;\n&quot;, $a);<br />
		break;<br />
	endswitch;</p>
<p>	return apply_filters( &#8216;dropdown_generate_tag_cloud&#8217;, $return, $tags, $args );<br />
}<br />
?&gt;<br />
[/php]</p>
<p>Now open the file where you want the list to be displayed and paste the following code:</p>
<p>[php]<br />
&lt;select name=&quot;tag-dropdown&quot; onchange=&quot;document.location.href=this.options[this.selectedIndex].value;&quot;&gt;<br />
	&lt;option value=&quot;#&quot;&gt;Tags&lt;/option&gt;<br />
	&lt;?php dropdown_tag_cloud(&#8216;number=0&amp;order=asc&#8217;); ?&gt;<br />
&lt;/select&gt;<br />
[/php]</p>
<p><span style="color: #ff99cc;">.via { <a href="http://www.webdesignerwall.com/tutorials/20-wordpress-recipes-codes/">WebdesignerWall</a> }</span></p>
]]></content:encoded>
			<wfw:commentRss>http://wpswitch.com/blog/display-wordpress-post-tags-in-a-dropdown-menu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Display The Number Of Your Twitter Followers in WordPress</title>
		<link>http://wpswitch.com/blog/display-number-twitter-followers-wordpress/</link>
		<comments>http://wpswitch.com/blog/display-number-twitter-followers-wordpress/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 02:20:10 +0000</pubDate>
		<dc:creator>WP Switch™</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Wordpress Hacks]]></category>
		<category><![CDATA[Wordpress HowTo]]></category>

		<guid isPermaLink="false">http://wpswitch.com/?p=1348</guid>
		<description><![CDATA[<p>Thanks for subscribing! <a href="http://wpswitch.com">WP Switch</a> - <a href="http://wpswitch.com">WP Switch - Premium WordPress Themes and Design Blog</a></p><p>So you have bazillions of followers on Twitter and you want to display your Twitter dominance to all the people who visit your blog huh? If you are not a fan of plugins you can display your follow count in plain text and style it to your liking later on. Paste the following php code [...]</p>]]></description>
			<content:encoded><![CDATA[<p>Thanks for subscribing! <a href="http://wpswitch.com">WP Switch</a> - <a href="http://wpswitch.com">WP Switch - Premium WordPress Themes and Design Blog</a></p><p>So you have bazillions of followers on Twitter and you want to display your Twitter dominance to all the people who visit your blog huh? If you are not a fan of plugins you can display your follow count in plain text and style it to your liking later on.<span id="more-1348"></span></p>
<p>Paste the following php code in the functions.php file from your WordPress blog theme&#8230;</p>
<p>[php]<br />
function string_getInsertedString($long_string,$short_string,$is_html=false){<br />
  if($short_string&gt;=strlen($long_string))return false;<br />
  $insertion_length=strlen($long_string)-strlen($short_string);<br />
  for($i=0;$i&lt;strlen($short_string);++$i){<br />
    if($long_string[$i]!=$short_string[$i])break;<br />
  }<br />
  $inserted_string=substr($long_string,$i,$insertion_length);<br />
  if($is_html &amp;&amp; $inserted_string[$insertion_length-1]==&#8217;&lt;&#8217;){<br />
    $inserted_string=&#8217;&lt;&#8217;.substr($inserted_string,0,$insertion_length-1);<br />
  }<br />
  return $inserted_string;<br />
}</p>
<p>function DOMElement_getOuterHTML($document,$element){<br />
  $html=$document-&gt;saveHTML();<br />
  $element-&gt;parentNode-&gt;removeChild($element);<br />
  $html2=$document-&gt;saveHTML();<br />
  return string_getInsertedString($html,$html2,true);<br />
}</p>
<p>function getFollowers($username){<br />
  $x = file_get_contents(&quot;http://twitter.com/&quot;.$username);<br />
  $doc = new DomDocument;<br />
  @$doc-&gt;loadHTML($x);<br />
  $ele = $doc-&gt;getElementById(&#8216;follower_count&#8217;);<br />
  $innerHTML=preg_replace(&#8216;/^&lt;[^&gt;]*&gt;(.*)&lt;[^&gt;]*&gt;$/&#8217;,&quot;\\1&quot;,DOMElement_getOuterHTML($doc,$ele));<br />
  return $innerHTML;<br />
}<br />
[/php]</p>
<p>Once you have done this you simply paste the following anywhere on your theme files. Just replace &#8220;wpswitch&#8221; with your Twitter username.</p>
<p>[php]&lt;?php echo getFollowers(&quot;wpswitch&quot;).&quot; followers&quot;; ?&gt;[/php]</p>
<p><span style="color: #ff99cc;">.via { <a href="http://www.wprecipes.com/display-the-total-number-of-your-twitter-followers-on-your-wordpress-blog">WpRecipes</a> }</span></p>
]]></content:encoded>
			<wfw:commentRss>http://wpswitch.com/blog/display-number-twitter-followers-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding a search bar to the NextGEN Gallery Plugin</title>
		<link>http://wpswitch.com/blog/adding-a-search-bar-to-the-nextgen-gallery-plugin/</link>
		<comments>http://wpswitch.com/blog/adding-a-search-bar-to-the-nextgen-gallery-plugin/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 01:48:51 +0000</pubDate>
		<dc:creator>WP Switch™</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://wpswitch.com/?p=1185</guid>
		<description><![CDATA[<p>Thanks for subscribing! <a href="http://wpswitch.com">WP Switch</a> - <a href="http://wpswitch.com">WP Switch - Premium WordPress Themes and Design Blog</a></p><p>This code allows you to be able to search for character names in the search bar, and for the engine to find it in the tag, titles, and descriptions of NextGen images and posts. In the folder for the theme you are using, look for search.php and functions.php. If you don&#8217;t have a search.php, you [...]</p>]]></description>
			<content:encoded><![CDATA[<p>Thanks for subscribing! <a href="http://wpswitch.com">WP Switch</a> - <a href="http://wpswitch.com">WP Switch - Premium WordPress Themes and Design Blog</a></p><p>This code allows you to be able to search for character names in the search bar, and for the engine to find it in the tag, titles, and descriptions of NextGen images and posts. <span id="more-1185"></span></p>
<p>In the folder for the theme you are using, look for search.php and functions.php. If you don&#8217;t have a search.php, you may use the index.php or you can make a search.php by copying the index.php.</p>
<p>In your search.php file, insert the following code at the place where you want the pictures to appear.</p>
<p>[php]<br />
&amp;lt;?php<br />
// Start of NextGen Gallery search<br />
if(is_search()) {<br />
$search = $wp_query-&amp;gt;get(&#8216;s&#8217;);<br />
$keywords = preg_replace(&#8216;/\+/&#8217;,&#8217; &#8216;,$search);<br />
if (function_exists (&#8216;ngg_get_search_pictures&#8217;)) {  // function from functions.php<br />
$nggpictures = ngg_get_search_pictures($keywords, &#8221;); // put the number of pictures by row you want, if you don&#8217;t want &amp;quot;4&amp;quot;</p>
<p>echo &amp;quot;&amp;lt;h2&amp;gt;Pictures&amp;lt;/h2&amp;gt;&amp;quot;;<br />
if ($nggpictures) {<br />
echo $nggpictures;<br />
echo &#8216;&amp;lt;div class=&amp;quot;clear&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/div&amp;gt;&#8217;;<br />
}<br />
else {<br />
echo &#8216;&amp;lt;p&amp;gt;No pictures were found.&amp;lt;/p&amp;gt;&#8217;;<br />
}<br />
}<br />
}<br />
// End of NextGen Gallery search<br />
?&amp;gt;<br />
[/php]</p>
<p>In my search.php, I put it outside the &#8220;if (have_posts())&#8221; section because I wanted to search pictures whether or not there were posts found.</p>
<p>Add the following code to the end of functions.php.</p>
<p>[php]<br />
&amp;lt;?php<br />
## Function to do search on gallery pics from NextGen Gallery plugin<br />
##<br />
## 2 vars : 	(1) $keywords (usually coming from the standard search query from wordpress)<br />
##		(2) $numberPicCol (number of pic by row, if null it takes 4 )<br />
function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {<br />
global $wpdb;<br />
//	$count=1;<br />
//	if (!$numberPicRow) { $numberPicRow = &amp;quot;4&amp;quot;; }</p>
<p>$nngquery = &amp;quot;<br />
SELECT pid,description,alttext<br />
FROM wp_ngg_pictures<br />
WHERE MATCH (description, filename, alttext) AGAINST (&#8216;$keywords&#8217; IN BOOLEAN MODE)<br />
AND exclude = &#8217;0&#8242;<br />
## start of tags code<br />
UNION<br />
SELECT pid,wp_ngg_pictures.description,alttext<br />
FROM wp_ngg_pictures, wp_terms, wp_term_taxonomy, wp_term_relationships<br />
WHERE wp_terms.term_id = wp_term_taxonomy.term_id and<br />
wp_term_taxonomy.taxonomy = &#8216;ngg_tag&#8217; and<br />
wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id and<br />
wp_term_relationships.object_id = wp_ngg_pictures.pid and<br />
MATCH (wp_terms.name) AGAINST (&#8216;$keywords*&#8217; IN BOOLEAN MODE)<br />
AND exclude = &#8217;0&#8242;<br />
## end of tags code<br />
&amp;quot;;<br />
$pictures = $wpdb-&amp;gt;get_results($nngquery, ARRAY_A);</p>
<p>if ($pictures) foreach($pictures as $pic) {</p>
<p>$out .= &#8216;&amp;lt;div class=&amp;quot;ngg-gallery-thumbnail&amp;quot;&amp;gt;&#8217;;<br />
$out .= &#8216;&amp;lt;a href=&amp;quot;&#8217;.nggGallery::get_image_url($pic[pid]).&#8217;&amp;quot; title=&amp;quot;&#8217;.stripslashes($pic[description]).&#8217;&amp;quot; class=&amp;quot;thickbox&amp;quot; rel=&amp;quot;singlepic&#8217;.$pic[pid].&#8217;&amp;quot;&amp;gt;&#8217;;<br />
$out .=  &#8216;&amp;lt;img src=&amp;quot;&#8217;.nggGallery::get_thumbnail_url($pic[pid]).&#8217;&amp;quot; alt=&amp;quot;&#8217;.stripslashes($pic[alttext]).&#8217;&amp;quot; title=&amp;quot;&#8217;.stripslashes($pic[alttext]).&#8217;&amp;quot; /&amp;gt;&#8217;;<br />
$out .=  &amp;quot;&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;\n&amp;quot;;<br />
// pictures use float left, so don&#8217;t need the code that outputs a &amp;lt;br /&amp;gt;<br />
//				if ($count == 0) {<br />
//				$out .= &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;;<br />
//				}<br />
//				++$count;<br />
//				$count%=$numberPicRow;<br />
}<br />
return $out;<br />
};<br />
?&amp;gt;<br />
[/php]</p>
<p>This code searches a picture&#8217;s file name, description, alternate text, and tags. I require an exact match for the first three because I was getting too many false positives using an inexact match. </p>
<p>The tag search looks for tags that start with the keyword. You can easily change the exact/inexact match behavior to suit yourself: In the AGAINST phrase, use &#8216;$keywords&#8217; to require an exact match and &#8216;$keywords*&#8217; for an inexact match. The first part of the SELECT searches file name, description, and alternate text, and the second part searches the tags.</p>
<p>This search method does have some peculiarities due to MySQL limitations: It will not find words that have less than 4 characters or are on this list. If you want to use short tags or ones on the list, I suggest adding enough characters to the end of the tag to remove the problem, then using an inexact search to find it. </p>
<p>Remember that your visitors cannot see the actual tag on the picture. In one of the discussion threads, a person was having problems with the tag &#8220;elk&#8221;; this is why. He could get around the problem by using &#8220;elkk&#8221; or &#8220;elk_&#8221; or &#8220;elk2&#8243; or any number of other variations on &#8220;elk&#8221;.</p>
<p><span style="color: #ff99cc;">.via { <a href="http://wordpress.org/support/topic/304105">WordPress Forums</a> from user <a href="http://wordpress.org/support/profile/4355475">nancyb7</a> }</span></p>
]]></content:encoded>
			<wfw:commentRss>http://wpswitch.com/blog/adding-a-search-bar-to-the-nextgen-gallery-plugin/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Retreive First Image From WordPress Post</title>
		<link>http://wpswitch.com/blog/retreive-first-image-wordpress-post/</link>
		<comments>http://wpswitch.com/blog/retreive-first-image-wordpress-post/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 00:44:07 +0000</pubDate>
		<dc:creator>WP Switch™</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://wpswitch.com/?p=370</guid>
		<description><![CDATA[<p>Thanks for subscribing! <a href="http://wpswitch.com">WP Switch</a> - <a href="http://wpswitch.com">WP Switch - Premium WordPress Themes and Design Blog</a></p><p>I have been looking around for this for ages. I have been using other post thumb plugins and just find them to bulky for what i wanted, too feature rich. I just wanted a basic grab the first image from a post and display it. Just add the below code to your functions.php file in [...]</p>]]></description>
			<content:encoded><![CDATA[<p>Thanks for subscribing! <a href="http://wpswitch.com">WP Switch</a> - <a href="http://wpswitch.com">WP Switch - Premium WordPress Themes and Design Blog</a></p><p>I have been looking around for this for ages. I have been using other post thumb plugins and just find them to bulky for what i wanted, too feature rich. I just wanted a basic grab the first image from a post and display it. Just add the below code to your functions.php file in your theme directory.<span id="more-370"></span></p>
<p>[php]<br />
// Get URL of first image in a post<br />
function get_first_image() {<br />
global $post, $posts;<br />
$first_img = &#8221;;<br />
ob_start();<br />
ob_end_clean();<br />
$output = preg_match_all(&#8216;/&lt;img.+src=[\'&quot;]([^\'&quot;]+)[\'&quot;].*&gt;/i&#8217;, $post-&gt;post_content, $matches);<br />
$first_img = $matches [1] [0];</p>
<p>// no image found display default image instead<br />
if(empty($first_img)){<br />
$first_img = &quot;/images/default.jpg&quot;;<br />
}<br />
return $first_img;<br />
}[/php]</p>
<p>To call it just put</p>
<p>[php]&lt;?php echo get_first_image() ?&gt;[/php]</p>
<p>in your template file within the loop.</p>
<p><span style="color: #ff99cc;">.via { <a href="http://wordpress.org/support/topic/246893">WordPress Forums</a> }</span></p>
]]></content:encoded>
			<wfw:commentRss>http://wpswitch.com/blog/retreive-first-image-wordpress-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

