Posts tagged code Page 2

jQuery Script for Loading More Posts

#

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('<a id="almc-load-more" href="' + $next_href + '">' + $text + '</a>');
	$('#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('<div class="almc-loaded" id="almc-' + $timestamp + '" />').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
		});
	});
});

Automatic Updates for Plugins and Themes Hosted Outside WordPress Extend

#

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’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 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.

Standalone Script for Clearing APC Cache

#

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') && $_GET['pass'] == 'secret') {
        if (apc_clear_cache() && apc_clear_cache('user'))
                print 'All Clear!';
        else
                print 'Clearing Failed!';
        print '<pre>';
        print_r(apc_cache_info());
        print '</pre>';
} else {
        print 'Authenticate, please!';
}

Then call the script via http://example.com/clearapc.php?pass=secret

Instead of using ?pass=secret, you might well call the filename something that is hard to guess: clearapc93920.php

Automatically Escape HTML Entities of Code Fragments in Comments

#

Update: Ryan has made this into a plugin — Code Comments.

Add this to your theme’s functions.php to allow readers post fragments of code in their comments (wrapped in <code>...</code>) which are automatically encoded (think of < and &lt;)

add_filter('pre_comment_content', 'encode_code_in_comment');

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

  if ($encoded)
    return $encoded;
  else
    return $source;
}

Worth noting:

  • Everything wrapped in <code>...</code> is encoded.
  • Line breaks after opening <code> and before closing </code> are removed in order to avoid unnecessary <br /> tags.

How to Create Beautiful and Elegant HTML Lists Using CSS

#

HTML list have become one of the most used HTML elements for marking-up various semantic content structures — 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 using specific HTML tags <ul> and <ol>, 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 certain relationship 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. Read more »

Logos and Names Are Not Headings

#

Illustration: Logo is not h1 It is a common trend among many web designers and developers to use h1 tag for a logo of a website. Although such decision has no impact on the visual presentation of the content, it drastically diminishes the semantic power of h1 tag.

Every page on the web can be viewed as a single document. Hypertext enables linking and organizing them into groups and sets, which requires that each document has a clear purpose and structure.

Domain names are unique identifiers of those different groups of documents and are the broadest description of their content. Therefore usually they already include the name of a business, person or product (I will refer to them as ‘logos’). Read more »