Jeśli jesteś właścicielem tej strony, możesz wyłączyć reklamę poniżej zmieniając pakiet na PRO lub VIP w panelu naszego hostingu już od 4zł!

Archive for Październik, 2010

WordPress categories, optimization tips and custom pages

WordPress categories, optimization tips and custom pages

It’s not a SEO secret, inner links to / from strong category pages will help your site to rank higher in Google. Sad enough that WordPress doesn’t provide a lot of functionality for these important sections on your blog site. This is the information you can read below the field “description” if you edit a category:

The description is not prominent by default, however some themes may show it.

There is no field for a second title and the description field doesn’t allow most of the HTML elements. I’m using the All in One SEO plugin because it gives me the freedom to write a custom page title or meta description (for posts or pages only). Most SEO plugins doesn’t care a lot about category pages…

First preparations

In my experience it’s the best to not index any archive page created by WordPress because they show content duplicates. The category URL could need an update first: By default you get this kind of category URL:

http://www.domain.com/archives/category/some-category-name

We need to remove the “archives” part from the URL, goto Settings->Permalinks and add some unique name for the field “Category base”.

If you use the “All in One SEO” like I do, disable the following settings:
Canonical URLs, Use noindex for Categories

Head to the plugin category, open the file (aioseop.class.php) and disable (//) row 283 to disable the creation of a meta description for all category pages:

//$description = $this->internationalize(category_description());

This function is buggy because the auto generate option will use the complete category text for a meta description.

We will create for the category pages our own META information and the canonical URLs for posts and pages are created by WordPress since version 2.9. Next you need to create some unique text for all the categories, 100 words is a great text length.

Optimizations for the “generated” category pages

We need to create some code to get the right META data in our header section. In the theme directory is a file called “functions.php”, open the file in a text editor and add this code:

function create_short_version($text, $len = 150) {
	$parts = explode(' ', $text);
	$ic = count($parts);
	$txt = '';
	for ($i = 0; $i < $ic; $i++) {
		$txt .= $parts[$i].' ';
		if (strlen($txt) >= $len) break;
	}
	$txt = trim($txt).'...';
	return $txt;
}
 
function fix_meta_canonical() {
	global $paged;
	if (is_category()) {
		$catid = get_query_var('cat');
		$catdescr = strip_tags(trim(category_description($catid)));
		if (strlen($catdescr) > 160) {
			$meta = create_short_version($catdescr);
		} else {
			$meta = $catdescr;
		}
		echo '
<link rel="canonical" href="'.get_category_link($catid).'" />
<meta name="description" content="'.$meta.'" />';
		if ($paged > 1) echo '
<meta name="robots" content="noindex,follow" />';
	} else {
		echo '';
	}
}
add_action('wp_head', 'fix_meta_canonical');

The first function “create_short_version()” is a helper which creates a short version from a text without changing the last word into something unreadable. Inside the function “fix_meta_canonical()” we create additional META information if the current page is a category. We don’t allow search engines to index other category pages than the first page.

Now we need to change our default theme file. Open the file “archive.php” (or category.php) and add the following code right below the header element and before the loop:

	<?php
	if (is_category() && $paged < 2) {
		echo '
		<p>'.category_description().'</p>';
	}
	?>

Using this code the category page will show the description as well, but only on the first page!

Optimize your most important categories

I use for most of my blog posts more than one category, for example this article is listed in the categories “PHP Scripts” and “Search engine optimization”. If you analyze your blog you will see that some category is more important or is used more often. While the steps above are okay for most the categories, it might be better to create a custom or static page for some of your categories. We did this for the category PHP Scripts.

With WordPress it’s possible to create a static page for just a single category. How does it work? Create a copy of the “archive.php” file and call it category-XX.php where XX is the category ID from the category you like to create a static page for. You can find the ID in the browser’s address bar if you edit a category. Add your custom code and the category description to this newly created file and save your work. I use the static content only for the first page and show the regular code for all underlying pages:

<?php
if (is_category() && $paged < 2) {
    // show here your custom code/content
} else {
    // show here the code from your archive.php file
}
?>

Don’t remove any code from outside the DIV container with the ID “content”. This modifications are only for the “information part” and about the design or the layout.

Header and title improvements

For SEO reasons it’s much better to have different titles in the page title and your header element. With the following code it’s possible to tweak the page title as well:

// create here your custom titles
$my_pagetitels = array(
	4 => 'PHP scripts and tutorials'
);
 
function change_cptitle() {
	global $my_pagetitels;
	$catid = get_query_var('cat');
	if (array_key_exists($catid, $my_pagetitels)) {
		$title = $my_pagetitels[$catid]; // use a custom title
    } else {
    	$title = get_the_category_by_ID($catid); // use the category name as title
    }
    return $title;
}
add_filter("single_cat_title", "change_cptitle");

Sure this solution is very quick and dirty, but it works :) Add your custom titles within the array which is called “$my_pagetitels”. Use the category ID as array index number and enter the “page title” as value. The function will check the array for an existing value and will use the category name as alternative. With a static value for your header element you use three different values instead of only one (the category name).

Don’t forget to add your category pages the Google Sitemap, and if you blocked them in your “robots.txt” file you need to allow the access too.

That’s all, for some tweaks you need to edit several WP theme files if you add or change a category, but I’m sure it worth the time and work! Don’t forget to create some external links to your category pages! If you have any questions or suggestion, you’re welcome to post them below.Similar Posts:


Source: http://feedproxy.google.com/~r/WebDevelopmentBlog/~3/WbzHx7yh2uE/

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Test.ical.ly Blog: What is a good software architecture in a nutshell?

Test.ical.ly Blog: What is a good software architecture in a nutshell?

On the Test.ical.ly blog there’s a recent post asking about good software architecture and how you could define it simply without having to muck around with all of the details it tends to conjure up.

What is a good architecture and why are there apparently two opposing trenches supporting quality on the one side and speed of development on the other side? After having had enough time to think about this whilst flying to Spain I came to the conclusion that Nils question whether it would be better to start quick and dirty to fail cheap in case the project is a looser or to stick to a clean and solid architecture and spend more time and money. Does quick always have to be dirty, clean always have to be slow, is dirty always quicker?

He suggests that “good architecture” and “quick and dirty” are the two opposite ends of the same spectrum. Instead, he suggests that a pragmatic approach is the best – focusing on what needs to be done rather that how to get there. Also by applying the “don’t fix it if it’s not broken” mentality to current methods and technologies, you can save a lot of hassle in the long run.

Source: http://www.phpdeveloper.org/news/15343

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

LogicPool.com: List of PHP and MySQL Code Generators

LogicPool.com: List of PHP and MySQL Code Generators

On the LogicPool site there’s a new post with a list of PHP+MySQL code generators you can use if there’s not a specific framework involved in your application (most of those come with code generation tools already).

Some of these tools can rapidly build a fully functional application, but there’s more to most useful applications than simply displaying a list of fields for users to fill out and viewing the results from an admin only accessible area. Most applications will need tweaks that can be small to large depending on the requirements. Keep that in mind when looking at these products as the amount of effort required to tweak the code produced by these tools.

Tools on their list (some free, some paid services) include:

Source: http://www.phpdeveloper.org/news/15342

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

CodeIgniter.com Blog: What’s Happening Now?

CodeIgniter.com Blog: What’s Happening Now?

If you’ve been wondering what the latest happenings are with the CodeIgniter framework but haven’t been able to find much outside of a few blog posts and email threads floating around, you’re in luck! They’ve just posted a great update to the main CodeIgniter site about the framework and its relation, ExpressionEngine.

I’d like to give you an update on what’s happening with CodeIgniter. 2.0’s code has been stable and in use by ExpressionEngine and MojoMotor for many months [...] CodeIgniter has always been born from ExpressionEngine, both in terms of its code as well as its very ability to exist, since the commercial arm of EllisLab provides the resources necessary to maintain an open source framework and surrounding community. That is still the case, so to gauge what’s happening with CodeIgniter, you can often look to ExpressionEngine.

They also talk about some of the recent posts to the ExpressionEngine blog (like these two) and some of the things they’re doing (EllisLab) to improve not only the quality of their software, their interaction with the community and how the code for the framework is managed.

Source: http://www.phpdeveloper.org/news/15341

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Ibuildings techPortal: DPCRadio: Plant Pyrus in your system – A guide to a plugin system

Ibuildings techPortal: DPCRadio: Plant Pyrus in your system – A guide to a plugin system

New on the Ibuildings techPortal today they’ve posted the latest DPCRadio episode as recorded at the Dutch PHP Conference 2010 – Helgi Thormar Thobjoernsson’s talk “Plant Pyrus in your system – A guide to a plugin system”.

One of the biggest parts of any plugin system is the part that deals with discovery, installation, upgrading, dependency handling, infrastructure and other equally boring things. An essential part of any plugin system yet everyone dreads writing it, and few actually take on the task of writing it. With Pyrus (the new PEAR installer) these tasks will not only be easy to do but also a joy. By embedding Pyrus in your application with its lavish new APIs you can use a tried and tested solution that hundred of thousands of people use every day on their command line, but you will be able to provide it right IN your tool,

You can listen to the episode in different ways – either via the in-page player or by downloading the mp3. If you’d like to listen to other great recordings from the conference you can also check out the full list of episodes.

Source: http://www.phpdeveloper.org/news/15340

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

SitePoint PHP Blog: 3 Lightweight Alternatives to phpMyAdmin

SitePoint PHP Blog: 3 Lightweight Alternatives to phpMyAdmin

On the SitePoint PHP blog, there’s a new post offering your three more lightweight database management solutions than the typical phpMyAdmin install.

For much of the time, developers just want to check some data, alter a few records, or back up the database. The phpMyAdmin and MonoQL zipped distributions range from 2MB to 7MB, and they’re overkill for most day-to-day administration. You’re using a sledgehammer to crack a peanut. Here are three lightweight MySQL administration alternatives you should consider. They’re all PHP-based, open source, and great for quick database tasks.

The three that made their short list are:

Others suggested in the comments include Chive and DBKiss.

Source: http://www.phpdeveloper.org/news/15339

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Community News: Latest Releases from PHPClasses.org

Community News: Latest Releases from PHPClasses.org

Source: http://www.phpdeveloper.org/news/15338

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Jeff Moser’s Blog: Notes from porting C# code to PHP

Jeff Moser’s Blog: Notes from porting C# code to PHP

In a new post to his blog Jeff Moser takes you through some of his experiences in port code from C# to PHP as a first-time PHPer and learning right from a book.

After years of hearing negative things about PHP, I had been led to believe that touching it would rot my brain. Ok, maybe that’s a bit much, but its reputation had me believe it was full of bad problems. Even the cool kids had issues with PHP. But I thought that it couldn’t be too bad because there was that one website that gets a few hits using a dialect of it. When Kaggle offered to sponsor a port of my TrueSkill C# code to PHP, I thought I’d finally have my first real encounter with PHP.

He starts with a few disclaimers, noting that the structure of the application was kept largely the same and that he didn’t go much into the web or database functionality that PHP’s well known for. He talks about the book he chose to learn from (Beginning PHP 5.3) and includes some excerpts from the author talking about the PHP language. He splits up the rest of the post into several different sections covering his thoughts on the whole process:

  • The Good Parts
  • The “When in Rome…” Parts
  • The “Ok, I guess” Parts
  • The Frustrating Parts

Unfortunately, the “Good” parts section is one of the smallest.

Source: http://www.phpdeveloper.org/news/15337

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Pumka.net: Why MySQL timestamp is 24 seconds different from PHP

Pumka.net: Why MySQL timestamp is 24 seconds different from PHP

On the Pumka.net blog, Anton Oliink has an interesting problem where his timestamp on the PHP side of his application was different than the one on his MySQL backend’s side – by 24 seconds, in fact.

You may find that timestamp value returned by MySQL UNIX_TIMESTAMP() function is 24 seconds grater than those returned by PHP functions and classes like strtotime(), mktime, DateTime::getTimestamp(), Zend_Date::getTimestamp().

As it turns out, the issue isn’t’ really an “issue” after all – it’s caused by MySQL’s compensation for leap seconds. He gives a few ways you can avoid it being an issue in your application, though: disable leap seconds, only convert to timestamps on the PHP side or just use the “unix_timestamp()” and “from_unixtime()” methods to work with the values.

Source: http://www.phpdeveloper.org/news/15336

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

ProDevTips.com: Multiple File Uploads with XHR and PHP

ProDevTips.com: Multiple File Uploads with XHR and PHP

New on ProDevTips.com there’s a quick tutorial that includes a snippet of code showing you how to upload larger images with the help of HTML5 and this Ajax uploder.

So the jQuery / Flash multiple file uploader has not really been working when it comes to heavy duty stuff “Flash player has crashed” is a common scenario after some six < 2MB pictures, problem is, it needs to be able to handle up to 50 of them. Therefore I decided to check out the HTML5 alternatives and eventually found a really good one. I did have to make some modifications to make the solution fit with my own scenario and I detail them below.

He talks about some minor modifications he made to the code (like adding in watermarks) and includes the code for the new “uploadImages()” function that will handle the upload, build a thumbnail and output a result to send back to the uploader for a pass or a fail on the status.

Source: http://www.phpdeveloper.org/news/15335

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>