<?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>Konstruktors&#187; code</title>
	<atom:link href="http://konstruktors.com/blog/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://konstruktors.com</link>
	<description>Web Design, WordPress and Performance Services</description>
	<lastBuildDate>Fri, 10 Feb 2012 00:09:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19894</generator>
	<atom:link rel='hub' href='http://konstruktors.com/?pushpress=hub'/>
		<item>
		<title>Use Sticky Posts as Category&#160;Description</title>
		<link>http://konstruktors.com/blog/wordpress/3364-sticky-posts-as-category-description/</link>
		<comments>http://konstruktors.com/blog/wordpress/3364-sticky-posts-as-category-description/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 14:24:56 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3364</guid>
		<description><![CDATA[On putukrejums.lv blog we use the &#8216;sticky&#8217;posts to add introductory information to all category pages (see here, for example). This approach is better than using the category description field because it allows for all the usual formatting options. Here is how to add sticky posts on top of their respective category index pages and hide them from [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://konstruktors.com/wp-content/uploads/2011/11/putukrejums-sticky-posts-category-introduction.jpg"><img class="alignnone size-medium wp-image-3369" title="Sticky posts as Category Description" src="http://konstruktors.com/wp-content/uploads/2011/11/putukrejums-sticky-posts-category-introduction-500x330.jpg" alt="Sticky posts as Category Description" width="500" height="330" /></a></p>
<p>On <a href="http://putukrejums.lv">putukrejums.lv</a> blog we use the &#8216;sticky&#8217;posts to add introductory information to all category pages (<a href="http://putukrejums.lv/tavas-kazas/">see here</a>, for example). This approach is better than using the category description field because it allows for all the usual formatting options.<span id="more-3364"></span></p>
<p>Here is how to add sticky posts on top of their respective category index pages and hide them from the rest of pages and indexes:</p>
<pre>add_action('pre_get_posts', 'alter_stickies');
function alter_stickies($query) {
	if (!$query-&gt;is_category &amp;&amp; !$query-&gt;is_single)
		$query-&gt;set('post__not_in', get_option('sticky_posts'));
}

add_filter('posts_orderby', 'sticky_orderby');
function sticky_orderby($orderby){
	global $wpdb;
	if (is_category())
		$orderby = "Field(". $wpdb-&gt;prefix ."posts.ID," . implode(',', get_option('sticky_posts')) . ") DESC, " . $orderby;
 	return $orderby;
}</pre>
<p>Add the <code>is-sticky</code> class to the post wrap for additional formatting control:</p>
<pre>add_filter('post_class', 'add_stickies_class');
function add_stickies_class($classes) {
	if (is_sticky())
		$classes[] = 'is-sticky';
	return $classes;
}</pre>
<h3>Redirect Sticky Posts to Their Category Index Page</h3>
<p>We don&#8217;t want the sticky posts to be available as individual posts that can be access via their permalinks because this information is already being displayed at the top of every category index page. Here is a simple filter to redirect all sticky posts to their category index pages:</p>
<pre>add_action('template_redirect', 'redirect_stickies');
function redirect_stickies() {
	global $wp_query;

	if (!is_single())
		return;
	$stickies = get_option('sticky_posts');
	if (empty($stickies))
		return;

 	if (in_array($wp_query-&gt;post-&gt;ID, $stickies))
		if ($cats = get_the_category($wp_query-&gt;post-&gt;ID))
			if ($cat = end($cats))
				wp_redirect(get_category_link($cat-&gt;cat_ID), '302');
}</pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/3177-exclude-sticky-posts-from-adjacent-post-links/' rel='bookmark' title='How to Exclude Sticky Posts from Adjacent Post&nbsp;Links'>How to Exclude Sticky Posts from Adjacent Post&nbsp;Links</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/667-show-ads-only-to-visitors-coming-from-search-engines/' rel='bookmark' title='Show Ads Only to Visitors Coming from Search&nbsp;Engines'>Show Ads Only to Visitors Coming from Search&nbsp;Engines</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/2610-jquery-script-for-loading-more-posts/' rel='bookmark' title='jQuery Script for Loading More&nbsp;Posts'>jQuery Script for Loading More&nbsp;Posts</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/3364-sticky-posts-as-category-description/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Automatically Add Image Credit or Source URL to Photo Captions in&#160;WordPress</title>
		<link>http://konstruktors.com/blog/wordpress/3203-how-to-automatically-add-image-credit-or-source-url-to-photo-captions-in-wordpress/</link>
		<comments>http://konstruktors.com/blog/wordpress/3203-how-to-automatically-add-image-credit-or-source-url-to-photo-captions-in-wordpress/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 16:32:44 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3203</guid>
		<description><![CDATA[Crediting and linking the source of any republished photo or illustration on the web is one of the most important best practices of web publishing. Unfortunately, there isn&#8217;t a standard way of doing it in WordPress and authors are left with their own decision on how and where to credit the original author or website. I [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_3205" class="wp-caption aligncenter" style="width: 510px"><img class="size-medium wp-image-3205 " title="Add image author or source URL to photos in WordPress" src="http://konstruktors.com/wp-content/uploads/2011/10/wordpress-image-photo-source-author-url-500x369.png" alt="Add image author or source URL to photos in WordPress" width="500" height="369" /><p class="wp-caption-text">Photo credit added automatically to every photo with a caption (via <a href="http://putukrejums.lv">putukrejums.lv</a>)</p></div>
<p>Crediting and linking the source of any republished photo or illustration on the web is one of the most important best practices of web publishing. Unfortunately, there isn&#8217;t a standard way of doing it in WordPress and authors are left with their own decision on how and where to credit the original author or website.<span id="more-3203"></span></p>
<p>I decided to add <strong>a simple &#8220;Source URL&#8221; input field to every image that is uploaded</strong>. Adding credit with a link to the source of that image now becomes as easy as adding a title or caption for an image:</p>
<p><a href="http://konstruktors.com/wp-content/uploads/2011/10/image-source-url-credit-dashboard.png"><img class="aligncenter size-medium wp-image-3206" title="Attached image Source URL input field" src="http://konstruktors.com/wp-content/uploads/2011/10/image-source-url-credit-dashboard-500x523.png" alt="Attached image Source URL input field" width="500" height="523" /></a></p>
<h3>Implementation</h3>
<p>You need to add the <a href="http://pastebin.com/FZJ3DJBg">following snippet of PHP</a> to your theme&#8217;s <code>functions.php</code>:</p>
<h4>Add the source URL input field to image upload screen</h4>
<pre>add_filter("attachment_fields_to_edit", "add_image_source_url", 10, 2);
function add_image_source_url($form_fields, $post) {
	$form_fields["source_url"] = array(
		"label" =&gt; __("Source URL"),
		"input" =&gt; "text",
		"value" =&gt; get_post_meta($post-&gt;ID, "source_url", true),
                "helps" =&gt; __("Add the URL where the original image was posted"),
	);
 	return $form_fields;
}

add_filter("attachment_fields_to_save", "save_image_source_url", 10 , 2);
function save_image_source_url($post, $attachment) {
	if (isset($attachment['source_url']))
		update_post_meta($post['ID'], 'source_url', esc_url($attachment['source_url']));
	return $post;
}</pre>
<h4>Automatically append the source URL to image captions</h4>
<pre>add_filter('img_caption_shortcode', 'caption_shortcode_with_credits', 10, 3);
function caption_shortcode_with_credits($empty, $attr, $content) {
	extract(shortcode_atts(array(
		'id'	=&gt; '',
		'align'	=&gt; 'alignnone',
		'width'	=&gt; '',
		'caption' =&gt; ''
	), $attr));

	// Extract attachment $post-&gt;ID
	preg_match('/\d+/', $id, $att_id);
	if (is_numeric($att_id[0]) &amp;&amp; $source_url = get_post_meta($att_id[0], 'source_url', true)) {
		$parts = parse_url($source_url);
		$caption .= ' ('. __('via') .' &lt;a href="'. $source_url .'"&gt;'. $parts['host'] .'&lt;/a&gt;)';
	}

	if (1 &gt; (int) $width || empty($caption))
		return $content;

	if ($id)
		$id = 'id="' . esc_attr($id) . '" ';

	return '&lt;div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px"&gt;'
		. do_shortcode($content) . '&lt;p class="wp-caption-text"&gt;' . $caption . '&lt;/p&gt;&lt;/div&gt;';
}</pre>
<p>Please note that the source URL will be visible only if you specify image caption upon inserting the image.</p>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/' rel='bookmark' title='Automatically Escape HTML Entities of Code Fragments in&nbsp;Comments'>Automatically Escape HTML Entities of Code Fragments in&nbsp;Comments</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/2890-add-rel-attribute-to-image-links-in-wordpress-galleries/' rel='bookmark' title='Add rel Attribute to Image Links in WordPress&nbsp;Galleries'>Add rel Attribute to Image Links in WordPress&nbsp;Galleries</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/92-take-away-photo-and-image-positioning-css-styles-for-blogs-idea-for-a-plugin/' rel='bookmark' title='Take-away photo and image positioning CSS styles for blogs &#8212; idea for a&nbsp;plugin'>Take-away photo and image positioning CSS styles for blogs &#8212; idea for a&nbsp;plugin</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/3203-how-to-automatically-add-image-credit-or-source-url-to-photo-captions-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Remove Inline CSS and Line Breaks in WordPress&#160;Galleries</title>
		<link>http://konstruktors.com/blog/wordpress/2920-remove-inline-css-line-breaks-galleries/</link>
		<comments>http://konstruktors.com/blog/wordpress/2920-remove-inline-css-line-breaks-galleries/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 22:07:55 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=2920</guid>
		<description><![CDATA[Inline CSS and line breaks &#60;br style="clear" /&#62; that are automatically added to the image galleries in WordPress is an example of how the needs of Automattic and WordPress.com influence the way new features are added to the WordPress core. So instead of editing every single theme on WordPress.com and adding the necessary CSS for [...]]]></description>
			<content:encoded><![CDATA[<p>Inline CSS and line breaks <code>&lt;br style="clear" /&gt;</code> that are automatically added to the image galleries in WordPress is an example of how the needs of Automattic and WordPress.com influence the way new features are added to the WordPress core. So instead of editing every single theme on WordPress.com and adding the necessary CSS for galleries to look good in all of them, they decided to put it WordPress core.</p>
<p>Here is how to replace those double line breaks with a single <code>&lt;br /&gt;</code> and remove the inline CSS:</p>
<pre><code>add_filter('the_content', 'remove_br_gallery', 11);
function remove_br_gallery($output) {
	return preg_replace('/(&lt;br[^&gt;]*&gt;\s*){2,}/', '&lt;br /&gt;', $output);
}

add_filter('use_default_gallery_style', '__return_false');
</code></pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/1899-smarter-cleaner-gallery/' rel='bookmark' title='Smarter Cleaner&nbsp;Gallery'>Smarter Cleaner&nbsp;Gallery</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/1770-multiple-galleries-per-post-page/' rel='bookmark' title='Multiple Galleries per&nbsp;Post/Page'>Multiple Galleries per&nbsp;Post/Page</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/3018-multiple-galleries-0-4/' rel='bookmark' title='Multiple Galleries&nbsp;0.4'>Multiple Galleries&nbsp;0.4</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/2920-remove-inline-css-line-breaks-galleries/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A Simple PHP Utility to Migrate Emails Between Two IMAP/POP&#160;Accounts</title>
		<link>http://konstruktors.com/blog/the-web/2915-php-migrate-emails-imap-pop/</link>
		<comments>http://konstruktors.com/blog/the-web/2915-php-migrate-emails-imap-pop/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 18:53:46 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=2915</guid>
		<description><![CDATA[I wrote this little (quick &#38; dirty) PHP command line utility to migrate around 10 email accounts from my IMAP server to Google Apps. Related posts How to Add Simple Google Site Search to Any&#160;Website OpenID Plugin and WordPress&#160;2.8 Self-hosted HTML5 Notepad App With&#160;Synchronization]]></description>
			<content:encoded><![CDATA[<p>I wrote this <a title="Migrate / transfer email from IMAP/POP to Google Apps" href="http://t.co/9qrMZZU">little (quick &amp; dirty) PHP command line utility</a> to migrate around 10 email accounts from my IMAP server to Google Apps.</p>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/web-design/2865-how-to-add-google-site-search/' rel='bookmark' title='How to Add Simple Google Site Search to Any&nbsp;Website'>How to Add Simple Google Site Search to Any&nbsp;Website</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/1241-openid-plugin-and-wordpress-2-8/' rel='bookmark' title='OpenID Plugin and WordPress&nbsp;2.8'>OpenID Plugin and WordPress&nbsp;2.8</a></li>
<li><a href='http://konstruktors.com/blog/the-web/2991-hosted-html5-notepad-app-sync/' rel='bookmark' title='Self-hosted HTML5 Notepad App With&nbsp;Synchronization'>Self-hosted HTML5 Notepad App With&nbsp;Synchronization</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/the-web/2915-php-migrate-emails-imap-pop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Script for Loading More&#160;Posts</title>
		<link>http://konstruktors.com/blog/wordpress/2610-jquery-script-for-loading-more-posts/</link>
		<comments>http://konstruktors.com/blog/wordpress/2610-jquery-script-for-loading-more-posts/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 21:42:32 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=2610</guid>
		<description><![CDATA[AKA Twitter, Facebook and Tumblr style. jQuery(document).ready(function($) { var $content = '#content'; var $nav_wrap = '.navigation'; var $anchor = '.navigation .alignleft a'; var $text = 'Load More'; var $next_href = $($anchor).attr('href'); // Get URL for the next set of posts $($nav_wrap).html('&#60;a id="almc-load-more" href="' + $next_href + '"&#62;' + $text + '&#60;/a&#62;'); $('#almc-load-more').click(function(e) { e.preventDefault(); $.get($(this).attr('href'), [...]]]></description>
			<content:encoded><![CDATA[<p>AKA Twitter, Facebook and Tumblr style.</p>
<pre><code>jQuery(document).ready(function($) {

	var $content = '#content';
	var $nav_wrap = '.navigation';
	var $anchor = '.navigation .alignleft a';
	var $text = 'Load More';

	var $next_href = $($anchor).attr('href'); // Get URL for the next set of posts

	$($nav_wrap).html('&lt;a id="almc-load-more" href="' + $next_href + '"&gt;' + $text + '&lt;/a&gt;');

	$('#almc-load-more').click(function(e) {
		e.preventDefault();

		$.get($(this).attr('href'), '', function(data) {
			var $timestamp = new Date().getTime();
			var $new_content = $($content, data).wrapInner('&lt;div class="almc-loaded" id="almc-' + $timestamp + '" /&gt;').html(); // Grab just the content
			$next_href = $($anchor, data).attr('href'); // Get the new href

			$('html,body').animate({scrollTop: $($nav_wrap).position().top}, 'slow'); // Animate scroll

			$($nav_wrap).before($new_content); // Append the new content
			$('#almc-' + $timestamp).hide().fadeIn('slow'); // Animate load
			$('#almc-load-more').attr('href', $next_href);	// Change the next URL
			$('.almc-loaded ' + $nav_wrap).remove(); // Remove the original navigation
		});
	});

});</code></pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/web-design/3384-embed-youtube-channel-playlist/' rel='bookmark' title='How to Embed Your YouTube Channel as a&nbsp;Playlist'>How to Embed Your YouTube Channel as a&nbsp;Playlist</a></li>
<li><a href='http://konstruktors.com/blog/web-design/1122-remove-border-from-image-links/' rel='bookmark' title='Remove Border from Image&nbsp;Links'>Remove Border from Image&nbsp;Links</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/3203-how-to-automatically-add-image-credit-or-source-url-to-photo-captions-in-wordpress/' rel='bookmark' title='How to Automatically Add Image Credit or Source URL to Photo Captions in&nbsp;WordPress'>How to Automatically Add Image Credit or Source URL to Photo Captions in&nbsp;WordPress</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/2610-jquery-script-for-loading-more-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic Updates for Plugins and Themes Hosted Outside WordPress&#160;Extend</title>
		<link>http://konstruktors.com/blog/wordpress/2538-automatic-updates-for-plugins-and-themes-hosted-outside-wordpress-extend/</link>
		<comments>http://konstruktors.com/blog/wordpress/2538-automatic-updates-for-plugins-and-themes-hosted-outside-wordpress-extend/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 12:21:44 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=2538</guid>
		<description><![CDATA[Here are two sample scripts along with an API to provide automatic updates for plugins and themes you host on your own server. Inside /api you&#8217;ll find index.php which processes all the update requests. You should place this in something like http://updates.example.com and update $api_url in /plugin/test-plugin-update/test-plugin-update.php and /theme/portfolio-racer/inc/updates.php accordingly. If you activate these sample [...]]]></description>
			<content:encoded><![CDATA[<p>Here are <a href="http://konstruktors.com/wp-content/uploads/2010/07/automatic-theme-plugin-update.zip">two sample scripts</a> along with an API to provide automatic updates for plugins and themes you host on your own server.</p>
<p>Inside <code>/api</code> you&#8217;ll find <code>index.php</code> which processes all the update requests. You should place this in something like <code>http://updates.example.com</code> and update <code>$api_url</code> in <code>/plugin/test-plugin-update/test-plugin-update.php</code> and <code>/theme/portfolio-racer/inc/updates.php</code> accordingly. If you activate these sample plugins without changing API URL, updates will be checked against my test server. If you decide to update, both plugin and theme will be replaced with exactly the same version of each.</p>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/1660-enable-automatic-updates-for-plugins-hosted-by-developers/' rel='bookmark' title='Enable Automatic Updates for Plugins Hosted by&nbsp;Developers'>Enable Automatic Updates for Plugins Hosted by&nbsp;Developers</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/1672-automatic-updates-for-developer-hosted-themes/' rel='bookmark' title='Automatic Updates for Developer Hosted&nbsp;Themes'>Automatic Updates for Developer Hosted&nbsp;Themes</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/1797-tabbed-widgets-updated-for-wordpress-2-8/' rel='bookmark' title='Tabbed Widgets Updated for WordPress&nbsp;2.8'>Tabbed Widgets Updated for WordPress&nbsp;2.8</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/2538-automatic-updates-for-plugins-and-themes-hosted-outside-wordpress-extend/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Standalone Script for Clearing APC&#160;Cache</title>
		<link>http://konstruktors.com/blog/web-design/2444-standalone-script-for-clearing-apc-cache/</link>
		<comments>http://konstruktors.com/blog/web-design/2444-standalone-script-for-clearing-apc-cache/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 12:48:59 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=2444</guid>
		<description><![CDATA[After upgrading WordPress to a new version, you might need to clear the APC opcode cache. Here is a simple script that you can store in the root of your website, for example, clearapc.php: if (function_exists('apc_clear_cache') &#38;&#38; $_GET['pass'] == 'secret') { if (apc_clear_cache() &#38;&#38; apc_clear_cache('user')) print 'All Clear!'; else print 'Clearing Failed!'; print '&#60;pre&#62;'; print_r(apc_cache_info()); [...]]]></description>
			<content:encoded><![CDATA[<p>After upgrading WordPress to a new version, you might need to clear the APC opcode cache. Here is a simple script that you can store in the root of your website, for example, <code>clearapc.php</code>:</p>
<pre><code>if (function_exists('apc_clear_cache') &amp;&amp; $_GET['pass'] == 'secret') {
        if (apc_clear_cache() &amp;&amp; apc_clear_cache('user'))
                print 'All Clear!';
        else
                print 'Clearing Failed!';

        print '&lt;pre&gt;';
        print_r(apc_cache_info());
        print '&lt;/pre&gt;';
} else {
        print 'Authenticate, please!';
}</code></pre>
<p>Then call the script via <code>http://example.com/clearapc.php?pass=secret</code></p>
<p>Instead of using <code>?pass=secret</code>, you might well call the filename something that is hard to guess: <code>clearapc93920.php</code></p>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/2382-clear-apc-cache-button-for-wordpress/' rel='bookmark' title='‘Clear APC Cache’ Button&nbsp;for WordPress'>‘Clear APC Cache’ Button&nbsp;for WordPress</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/2610-jquery-script-for-loading-more-posts/' rel='bookmark' title='jQuery Script for Loading More&nbsp;Posts'>jQuery Script for Loading More&nbsp;Posts</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/web-design/2444-standalone-script-for-clearing-apc-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>‘Clear APC Cache’ Button&#160;for WordPress</title>
		<link>http://konstruktors.com/blog/wordpress/2382-clear-apc-cache-button-for-wordpress/</link>
		<comments>http://konstruktors.com/blog/wordpress/2382-clear-apc-cache-button-for-wordpress/#comments</comments>
		<pubDate>Sat, 01 May 2010 21:22:44 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=2382</guid>
		<description><![CDATA[Here is a quick way to clear APC opcode cache with a single click within your WordPress dashboard &#8212; simply add this to your theme&#8217;s functions.php: if (function_exists('apc_clear_cache')) { // Clear cache if something is edited if (!empty($_POST) &#38;&#38; is_admin()) apc_clear_cache(); // Add Clear APC menu under Tools menu add_action('admin_menu', 'php_apc_info'); function php_apc_info() { add_submenu_page('tools.php', [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick way to clear APC opcode cache with a single click within your WordPress dashboard<span id="more-2382"></span> &#8212; simply add this to your theme&#8217;s <code>functions.php</code>:</p>
<pre><code>if (function_exists('apc_clear_cache')) {
	// Clear cache if something is edited
	if (!empty($_POST) &amp;&amp; is_admin())
		apc_clear_cache();

	// Add Clear APC menu under Tools menu
	add_action('admin_menu', 'php_apc_info');
	function php_apc_info() {
		add_submenu_page('tools.php', 'Clear APC', 'Clear APC', 'activate_plugins', 'clear_php_apc', 'php_apc_options');
	}
	function php_apc_options() {
		if (apc_clear_cache() &amp;&amp; apc_clear_cache('user'))
			print '&lt;p&gt;All Clear!&lt;/p&gt;';
		else
			print '&lt;p&gt;Clearing Failed!&lt;/p&gt;';
		print '&lt;pre&gt;'; print_r(apc_cache_info()); print '&lt;/pre&gt;';
	}

	// Add Clear APC in the favorite actions dropdown
	add_filter('favorite_actions', 'clear_apc_link');
	function clear_apc_link($actions) {
		$actions['tools.php?page=clear_php_apc'] = array('Clear APC', 'edit_posts');
		return $actions;
	}
}</code></pre>
<p>And the result looks like this:</p>
<p><img class="aligncenter size-full wp-image-2396" title="Clear APC cache menu item" src="http://konstruktors.com/wp-content/uploads/2010/05/clear-apc-cache-wordpress-e1272748867586.png" alt="Clear APC cache menu item" width="500" height="248" /></p>
<p>p.s. It seems that WordPress doesn&#8217;t like newline returns inside <code>&lt;pre&gt;</code>.</p>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/web-design/2444-standalone-script-for-clearing-apc-cache/' rel='bookmark' title='Standalone Script for Clearing APC&nbsp;Cache'>Standalone Script for Clearing APC&nbsp;Cache</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/2521-ajax-cache-purge-cookie-plugin/' rel='bookmark' title='AJAX Cache Purge Cookie&nbsp;Plugin'>AJAX Cache Purge Cookie&nbsp;Plugin</a></li>
<li><a href='http://konstruktors.com/blog/web-design/2374-php-apc-potential-cache-slam-averted-for-key/' rel='bookmark' title='PHP APC Potential Cache Slam Averted for&nbsp;Key'>PHP APC Potential Cache Slam Averted for&nbsp;Key</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/2382-clear-apc-cache-button-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically Escape HTML Entities of Code Fragments in&#160;Comments</title>
		<link>http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/</link>
		<comments>http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 03:51:52 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[filter]]></category>

		<guid isPermaLink="false">http://konstruktors.com/blog/?p=1850</guid>
		<description><![CDATA[Update: Ryan has made this into a plugin &#8212; Code Comments. Add this to your theme&#8217;s functions.php to allow readers post fragments of code in their comments (wrapped in &#60;code&#62;...&#60;/code&#62;) which are automatically encoded (think of &#60; and &#38;lt;) add_filter('pre_comment_content', 'encode_code_in_comment'); function encode_code_in_comment($source) { $encoded = preg_replace_callback('/&#60;code&#62;(.*?)&#60;\/code&#62;/ims', create_function( '$matches', '$matches[1] = preg_replace( array("/^[\r&#124;\n]+/i", "/[\r&#124;\n]+$/i"), "", [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: <em><a href="http://ryanhellyer.net/">Ryan</a> has made this into a plugin &#8212; <a href="http://pixopoint.com/code-comments/">Code Comments</a></em>.</p>
<p>Add this to your theme&#8217;s <code>functions.php</code> to allow readers post fragments of code in their comments (wrapped in <code>&lt;code&gt;...&lt;/code&gt;</code>) which are automatically encoded (think of <code>&lt;</code> and <code>&amp;lt;</code>)</p>
<pre>add_filter('pre_comment_content', 'encode_code_in_comment');

function encode_code_in_comment($source) {
  $encoded = preg_replace_callback('/&lt;code&gt;(.*?)&lt;\/code&gt;/ims',
  create_function(
    '$matches',
    '$matches[1] = preg_replace(
        array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "",
        $matches[1]);
      return "&lt;code&gt;" . htmlentities($matches[1]) . "&lt;/code&gt;";'
  ),
  $source);

  if ($encoded)
    return $encoded;
  else
    return $source;
}</pre>
<h3>Worth noting:</h3>
<ul>
<li>Everything wrapped in <code>&lt;code&gt;...&lt;/code&gt;</code> is encoded.</li>
<li>Line breaks after opening <code>&lt;code&gt;</code> and before closing <code>&lt;/code&gt;</code> are removed in order to avoid unnecessary <code>&lt;br /&gt;</code> tags.</li>
</ul>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/3203-how-to-automatically-add-image-credit-or-source-url-to-photo-captions-in-wordpress/' rel='bookmark' title='How to Automatically Add Image Credit or Source URL to Photo Captions in&nbsp;WordPress'>How to Automatically Add Image Credit or Source URL to Photo Captions in&nbsp;WordPress</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/2920-remove-inline-css-line-breaks-galleries/' rel='bookmark' title='Remove Inline CSS and Line Breaks in WordPress&nbsp;Galleries'>Remove Inline CSS and Line Breaks in WordPress&nbsp;Galleries</a></li>
<li><a href='http://konstruktors.com/blog/web-design/125-how-to-create-beautiful-and-elegant-html-lists-using-css/' rel='bookmark' title='How to Create Beautiful and Elegant HTML Lists Using&nbsp;CSS'>How to Create Beautiful and Elegant HTML Lists Using&nbsp;CSS</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How to Create Beautiful and Elegant HTML Lists Using&#160;CSS</title>
		<link>http://konstruktors.com/blog/web-design/125-how-to-create-beautiful-and-elegant-html-lists-using-css/</link>
		<comments>http://konstruktors.com/blog/web-design/125-how-to-create-beautiful-and-elegant-html-lists-using-css/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 22:40:01 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://konstruktors.com/blog/design-suggetions/125-how-to-create-beautiful-and-elegant-html-lists-using-css/</guid>
		<description><![CDATA[HTML list have become one of the most used HTML elements for marking-up various semantic content structures &#8212; navigation, comments and even image galleries. This article will explain and show you how to style lists inside blog posts, articles or other basic HTML documents. Before we start, it is necessary to understand the importance of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://konstruktors.com/wp-content/uploads/2008/02/anatomy-of-html-lists-unordered-ordered.png"><img class="aligncenter size-medium wp-image-129" title="Anatomy of HTML lists, unordered, ordered" src="http://konstruktors.com/wp-content/uploads/2008/02/anatomy-of-html-lists-unordered-ordered-500x290.png" alt="" width="500" height="290" /></a></p>
<p>HTML list have become one of the most used HTML elements for marking-up various semantic content structures &#8212; navigation, comments and even image galleries.</p>
<p>This article will explain and show you how to style lists inside blog posts, articles or other basic HTML documents.</p>
<p>Before we start, it is necessary to understand the importance of using specific HTML tags <code>&lt;ul&gt;</code> and <code>&lt;ol&gt;</code>, instead of simple numbering (like 1., 2. or •, ») for building lists. By applying content a semantic structure, we emphasize the relationships between different content elements. In case of lists we are able to imply that there is a <em>certain relationship</em> between all of the list members, which is possibly described by the paragraph introducing the list. It also helps screen reader users for whom the total number of items is announced before the rest of the list.<span id="more-125"></span></p>
<h3>Default list rendering in standards aware browsers and Internet Explorer</h3>
<p>Let&#8217;s look at the default rendering of ordered <code>&lt;ol&gt;</code> and unordered <code>&lt;ul&gt;</code> lists by Web standards aware browsers (with Gecko, Webkit or Opera rendering engine) and Internet Explorer (IE).</p>
<p><a href="http://konstruktors.com/wp-content/uploads/2008/02/list-rendering-standards-ie-thumb.png"><img class="aligncenter size-full wp-image-133" title="HTML list rendering. standards vs internet explorer" src="http://konstruktors.com/wp-content/uploads/2008/02/list-rendering-standards-ie-thumb.png" alt="" width="400" height="186" /></a></p>
<div class="image wide"></div>
<p>It turns out that IE applies default left side <strong>margin</strong> to the list container (<code>&lt;ul&gt;</code> and <code>&lt;ol&gt;</code>) while standards aware browsers apply left side <strong>padding</strong>. These differences in list rendering force us to set both padding and margin of <code>&lt;ul&gt;</code> to 0 and continue to work only with styling <code>&lt;li&gt;</code> tag.</p>
<p>Another thing we notice is that list bullets or numbering becomes invisible in IE with the left side margin set to 0.</p>
<h3>Getting the list rendering consistent among all browsers</h3>
<p>To solve the <em>invisible bullet</em> problem described above, its a good idea to use relative positioning of list containers <code>&lt;ul&gt;</code> and <code>&lt;ol&gt;</code>. By doing so, we will be able to create much more advanced list style later without repeating most of the CSS.</p>
<h4>CSS for simple lists</h4>
<pre lang="css">ul, ol {
   margin:auto -3em 1em 0;
   padding:0;
   position:relative;
   left:-3em;
   overflow:hidden;
}

li {
   margin-top:0.25em;
   margin-bottom:0.25em;
}

ul ul, ul ol,
ol ol, ol ul {
   margin-left:1em;
   padding-left:0;
}

ul li, ol li {
   margin-left:5em;
}

li li {
   margin-left:1em;
}</pre>
<h4>Internet Explorer specific CSS</h4>
<p>To fix IE&#8217;s ability to do the math correctly, we have to enable <a href="http://www.satzansatz.de/cssd/onhavinglayout.html">hasLayout</a> property for all of our <code>&lt;ul&gt;</code> and <code>&lt;ol&gt;</code> tags. This is done by using <a title="Read about conditional comments and how are they used for targeting different versions of IE" href="http://www.quirksmode.org/css/condcom.html">conditional comments</a>:</p>
<pre lang="html">ul, ol { height:0; overflow:visible; }
ul, ol { height:1%; }</pre>
<h5>Output</h5>
<p><img class="alignright" src="http://konstruktors.com/wp-content/uploads/2008/02/list-anatomy-simple-unordered.png" alt="Simple unordered list" width="200" height="170" /></p>
<p>List is now rendered equally in all browsers. For illustration purposes a yellow background is applied to the list container <code>&lt;ul&gt;</code>, gray border shows the dimensions of <code>&lt;ul&gt;</code>, while list items <code>&lt;li&gt;</code> have gray background.</p>
<h3><em>Flat</em> lists for more content per list item</h3>
<p>Sometimes you have multiple lines of content per list item and then it might be reasonable to align the lists with the rest of the content in order to sustain the vertical flow of it.</p>
<h4>CSS for <em>flat</em> lists</h4>
<pre lang="css">.flat li {
   margin-left:3em;
}

.flat li ul, .flat li ol {
   margin-left:1em;
   padding-left:0;
}

.flat li li {
   margin-left:0;
}</pre>
<p><img class="alignright" src="http://konstruktors.com/wp-content/uploads/2008/02/list-anatomy-flat-unordered.png" alt="Screenshot: flat HTML lists for more content" width="200" height="167" /></p>
<p>Notice the little amount of CSS, but more importantly that it is rendered equally among all of the browsers and we can still use the default bullet styles instead of images.</p>
<p>However, sometimes one might want to use custom style list bullets. This can be done using the <code>list-style-image</code> property in CSS.</p>
<h4>Lists with <em>custom style bullets</em></h4>
<p><img class="alignright" src="http://konstruktors.com/wp-content/uploads/2008/02/list-anatomy-unordered-custom-bullet-image.png" alt="Screenshot: HTML lists with custom bullet image" width="200" height="472" /></p>
<p><em>Note:</em> don&#8217;t forget to remove the line break after <code>list-style-image:</code> to get it working.</p>
<h4>CSS:</h4>
<pre lang="css">ul.bullet-a li {
   list-style-image:
    url('bullet-image-a.png');
}

ul.bullet-b li {
   list-style-image:
    url('bullet-image-b.png');
}</pre>
<p>Although the alignment of the list image is not pixel perfect among all of the browsers, it is more than satisfactory if the height of the bullet image doesn&#8217;t exceed 10 pixels. One might suggest to use background of <code>&lt;li&gt;</code> tag as a list bullet image, but this would brake the ability to combine multiple CSS identifiers per list, like <code>&lt;ul class="flat bullet-a"&gt;</code> because of inherited margin settings.</p>
<h3>All the small details</h3>
<p>Notice that the spacing between list items in the last example (rounded image bullets) is larger than the default one (arrow image bullets). This enhances readability and separates list items similarly to paragraphs. So here is the final set of CSS styles to suite most of the needs:</p>
<pre lang="css">.spaced {
    margin-bottom:0;
}

.spaced ul, .spaced ol {
    margin-top:1em;
}

.spaced li {
    margin-bottom:1em;
}</pre>
<pre lang="css">.indent li {
    padding-left:1em;
    text-indent:-1em;
}

.inside li {
    list-style-position:inside;
}

.clear li {
    list-style-type:none;
}</pre>
<p>You can see that one of the previous examples already utilizes the &#8220;spaced&#8221; styling, while &#8220;indent&#8221;, &#8220;inside&#8221; and &#8220;clear&#8221; might benefit from a few examples:</p>
<p style="text-align: center;"><img class="aligncenter" src="http://konstruktors.com/wp-content/uploads/2008/02/indent-flat-clear-inside-html-lists.png" alt="Screenshot: Flat and indented list, clear list, inside list" width="450" height="137" /></p>
<h3>All of CSS combined &amp; list style cheat-sheet</h3>
<ul class="flat">
<li><a href="http://konstruktors.com/wp-content/uploads/2008/02/index.html">View all of the list style examples</a> in your browser.</li>
<li>View the resulting CSS as <a title="CSS for beautiful HTML lists" href="http://konstruktors.com/wp-content/uploads/2008/02/konstruktors-lists.css">a seperate file</a> (bullet images: <a title="Sample bullet image a" href="http://konstruktors.com/wp-content/uploads/2008/02/bullet-image-a.png"><img class="inline" src="http://konstruktors.com/wp-content/uploads/2008/02/bullet-image-a.png" alt="Sample bullet image a" /></a> <a title="Sample bullet image b" href="http://konstruktors.com/wp-content/uploads/2008/02/bullet-image-b.png"><img class="inline" src="http://konstruktors.com/wp-content/uploads/2008/02/bullet-image-b.png" alt="Sample bullet image b" /></a>)</li>
<li><a title="HTML list style CSS cheat sheet" href="http://konstruktors.com/wp-content/uploads/2008/02/konstruktors-html-list-cheat-sheet.pdf"> Download a list style CSS classname cheat-sheet</a> (.pdf) which you can print and use as a reference when composing your articles, blog posts or other HTML documents.</li>
</ul>
<h3>Screenshot showing the use of various HTML list styles</h3>
<p style="text-align: center;"><a href="http://konstruktors.com/wp-content/uploads/2008/02/list-example-result.png"><img class="withborder aligncenter" src="http://konstruktors.com/wp-content/uploads/2008/02/list-example-result-thumb.png" alt="List output example" width="450" height="306" /></a></p>
<h4>Internet Explorer specific HTML and CSS</h4>
<pre lang="html">ul, ol { height:0; overflow:visible; }
ul, ol { height:1%; }</pre>
<h3>Few suggestions:</h3>
<ul class="flat">
<li>Bullet image height preferably should not exceed 10 pixels. Lower image height makes them look better in Internet Explorer. If you want bullet images to be transparent, save them as transparent GIF or 8-bit PNG files.</li>
<li>You might find it useful to apply this styling only to your post content, which can be easily done by prepeding the identifier of your post wrapper (like <code>.post</code> or <code>.article</code>) to all of the list styles. The end result would be something like <code>.post ul, .post ol {}</code>.</li>
</ul>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/web-design/755-minimize-wordpress-2-7-dashboard-header/' rel='bookmark' title='Squeeze the Header of the New WordPress 2.7&nbsp;Dashboard'>Squeeze the Header of the New WordPress 2.7&nbsp;Dashboard</a></li>
<li><a href='http://konstruktors.com/blog/web-design/2899-replace-login-logo-with-site-name-link/' rel='bookmark' title='Replace WordPress Login Logo With Your Site&#8217;s Name and&nbsp;Link'>Replace WordPress Login Logo With Your Site&#8217;s Name and&nbsp;Link</a></li>
<li><a href='http://konstruktors.com/blog/web-design/2036-remove-index-html-from-the-url/' rel='bookmark' title='Remove index.html from the&nbsp;URL'>Remove index.html from the&nbsp;URL</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/web-design/125-how-to-create-beautiful-and-elegant-html-lists-using-css/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
	</channel>
</rss>
