Using .htaccess to rewrite your URL

April 16th, 2009 Script Posted in Ebooks - Tips, Others No Comments » 110 views

If you want your website to have friendly URLs you can use this .htaccess code. With this example code, the URL http://www.w3code.net/about would cause the page about.html to load.

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]

With the above example, if there is no dot in the requested name (this prevents executing the filename lookup logic for every file request), and the request matches a filename (with a .html on the end), it will take the request and put .html on the end.

There are two restrictions with this method. Make sure there is not a directory with the same name as the url you are using (if using http://www.w3code.net/about - make sure there is not a directory named about), or you may get undesired results. And the page you wish to load cannot have a dot in the name (i.e. about.me.htm will not work).

Here is a second method. This one does not do a filename check so it is faster, but it could also do a rewrite when there is no file.

RewriteEngine On
RewriteRule ^([^\./]+)$ $1.html [L]

With the above example, if there is no dot or slash in the requested name, and the request is not empty (meaning the default page), it will take the request and put .html on the end.

There are also two restrictions with this method. Make sure there is not a directory with the same name as the url you are using (if using http://www.w3code.net/about - make sure there is not a directory named about), or you may get undesired results. And the page you wish to load cannot have a dot or slash in the name (i.e. about.me.html or sub/about.html will not work).

You can make any number of variations as to the criteria using these examples as a starting point.

AddThis Social Bookmark Button

Add-Ons & Tools for your Blogger

April 11th, 2009 Script Posted in Ebooks - Tips, SEO tool No Comments » 139 views

Adding Widgets, Add-Ons & tools to your blog is not just a lot of fun for your blog readers, but can also be very useful and help you to create a community for your blog or even a loyal reader base.

Here’s a collection of best and most useful blog widgets or add-ons that can be easily integrated with any website/blog. All these below add-ons are 100% Free and they are very easy to install.

Outbrain Star Ratings Widget: Very eager to know what your readers think about your posts? Here is a cool star rating widget by Outbrain. The insttallation is very simple, just follow the step by step instructions on their site.

ShareThis or AddThis : Sharethis or Addthis social bookmarking buttons makes it easy for your visitors to share your content with others. It is a good way to increase your link popularity and publicity. Their nice css dropdown icons reduces the clutter on your pages and eliminates the need to add a different button for each social bookmarking service.

whos.amung.us : This is a real time visitor tracking widget and displays
the number of people currently on your site and what pages they are
reading. You don’t need any sign-up’s to grab this widget.

Web2PDF Online : With this widget installed, your visitors can easily download your articles in PDF format with just a click. The downloaded PDF’s are free of any advertising and you can get full access to download stats,etc.

ZOHO Creator: With Zoho Creator, you can create professional online
contact forms/web forums in minutes. The good things about this is
there are no data limits and readers can also upload attachments while
submitting the form.

Google Talk Badge: Google Talk Badge will let your visitors to chat with you.The badge will active whenever you sign in to Googletalk. The nice thing is your visitors can chat with you even if they don’t have a google account.

Yahoo Media Player: With this very useful widget, you caneasily add a simple media player to your blog which can auto detect mp3 links and create an embedded player. This tool is very useful for especially audio,music blogs.

Cbox: Cbox or Chatbox is a chat widget which can be easily embedded
in any web page. It is free and have many features including message
history, spam blocking,etc. It can be easily customizable to fit your
blog layout.

Google Translate: This widget lets your non-English speaking visitors to quickly translate your webpage in their native language with just a single click.

AddThis Social Bookmark Button

How to convert Wordpress to Blogger ?

April 11th, 2009 Script Posted in Ebooks - Tips, How to No Comments » 81 views

Blogger is getting better and there could be bloggers wanting to import and convert their Wordpress blog to Blogger blog. Wordpress has in-built feature (under ‘tools’ tab) to import any Blogger blog. However, reverse conversion of Wordpress blog to Blogger blog is not supported.

Well, not anymore - you can convert your Wordpress blog to Blogger blog. Wordpress2Blogger web service provide a dead simple way for this conversion. To get started, login into your Wordpress blog then goto ‘Manage’ or ‘Tools’ tab and look for export option. Using this option download Wordpress WXR export file.

Now upload this file to Wordpress2Blogger online service to make it Blogger compatible. Download the resultant file and upload it into Blogger blog using import feature in Blogger dashboard. Your Wordpress posts should start appearing in Blogger blog. This method is suitable for smaller blogs with export / import files less than 1MB.

In case you want more technical way for Wordpress to Blogger conversion then checkout Google Blog Converter project. As pointed by Google OpenSource blog “… This new Open Source project provides the ability to easily move blog posts and comments from service to service. This initial release provides Python libraries and runnable scripts that convert between the export formats of Blogger, LiveJournal, MovableType, and WordPress.”

AddThis Social Bookmark Button

How to import /export xml file Blogger ?

April 11th, 2009 Script Posted in Ebooks - Tips, How to No Comments » 98 views

Long back in June Blogger introduced Blogger import / export feature along with loads of other new Blogger features. Import - export feature just got better and now support very large blogger blogs.

HOW TO IMPORT / EXPORT BLOGGER BLOG?

Instead of using www.blogger.com, use draft.blogger.com and sign into your blogger account. Then click on ’settings’ button. You will see ‘import blog’, ‘export blog’ and ‘delete blog’ button as shown in image above.

As pointed by Blogger blog, make sure you first test this feature on a temporary throw away blog. Also, currently it only support importing Blogger blogs. “… We don’t yet support importing from WordPress, Typepad, LiveJournal or any other blogging platforms.”

So, is suport for importing from Wordpres, Typepad etc is in MAKING? If yes, then this is great and Blogger will rock more and more!

AddThis Social Bookmark Button

Fix Unable to create directory with Wordpress

April 8th, 2009 Script Posted in Ebooks - Tips, How to 1 Comment » 565 views

I’m having issues uploading images to to a post. I keep getting the following error:

Unable to create directory /var/www/vhosts/domain.com/httpdocs/wp-content/uploads/2008/05. Is its parent directory writable by the server?

1. Firstly, on my test install, file uploads wouldn’t work and I got the “HTTP Error”. This was fixed with the addition to the .htaccess (in the top level of your Wordpress install).

I added the first four lines below to my .htaccess, so this is what I ended up with.

<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

2. Second: I am using WP 2.6. I CH’MOD (777) the following directories:

I found: wp-conten/ uploads, If not create this folder name:  uploads

I then went to Settings > Miscellaneous > Full URL path to files (optional)

I put in: http://asia-dns.net/wp-content/uploads

And made sure my uploads were set to:

wp-content/uploads

Testing Success this problem, Reupload and test on your upload site. Done

AddThis Social Bookmark Button

Google PageRank status display on your page

April 7th, 2009 Script Posted in Ebooks - Tips, PHP script No Comments » 296 views

What is Google PageRank?:

PageRank is a numeric value that represents how important a page is on the web. It is Google’s way of measuring the importance of web site.

Here is how Google explains PageRank:

PageRank relies on the uniquely democratic nature of the web by using its vast link structure as an indicator of an individual page’s value. Google interprets a link from page A to page B as a vote, by page A, for page B. But Google looks at more than the sheer volume of votes, or links a page receives; it also analyzes the page that casts the vote. Votes cast by pages that are themselves “important” weigh more heavily and help to make other pages “important.”

Firstly, Open Notepad - Copy - Paste and save File name:  pagerank.php

<?php
define(’GOOGLE_MAGIC’, 0xE6359A60);
class pageRank{
var $pr;
function zeroFill($a, $b){
$z = hexdec(80000000);
if ($z & $a){
$a = ($a>>1);
$a &= (~$z);
$a |= 0×40000000;
$a = ($a>>($b-1));
}else{
$a = ($a>>$b);
}
return $a;
}

function mix($a,$b,$c) {
$a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,13));
$b -= $c; $b -= $a; $b ^= ($a<<8);
$c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,13));
$a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,12));
$b -= $c; $b -= $a; $b ^= ($a<<16);
$c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,5));
$a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,3));
$b -= $c; $b -= $a; $b ^= ($a<<10);
$c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,15));
return array($a,$b,$c);
}

function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
if(is_null($length)) {
$length = sizeof($url);
}
$a = $b = 0×9E3779B9;
$c = $init;
$k = 0;
$len = $length;
while($len >= 12) {
$a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
$b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
$c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
$mix = $this->mix($a,$b,$c);
$a = $mix[0]; $b = $mix[1]; $c = $mix[2];
$k += 12;
$len -= 12;
}
$c += $length;
switch($len){
case 11: $c+=($url[$k+10]<<24);
case 10: $c+=($url[$k+9]<<16);
case 9 : $c+=($url[$k+8]<<8);
/* the first byte of c is reserved for the length */
case 8 : $b+=($url[$k+7]<<24);
case 7 : $b+=($url[$k+6]<<16);
case 6 : $b+=($url[$k+5]<<8);
case 5 : $b+=($url[$k+4]);
case 4 : $a+=($url[$k+3]<<24);
case 3 : $a+=($url[$k+2]<<16);
case 2 : $a+=($url[$k+1]<<8);
case 1 : $a+=($url[$k+0]);
}
$mix = $this->mix($a,$b,$c);
/* report the result */
return $mix[2];
}

//converts a string into an array of integers containing the numeric value of the char

function strord($string) {
for($i=0;$i<strlen($string);$i++) {
$result[$i] = ord($string{$i});
}
return $result;
}

function printrank($url){
$ch = “6″.$this->GoogleCH($this->strord(”info:” . $url));

$fp = fsockopen(”www.google.com”, 80, $errno, $errstr, 30);
if (!$fp) {
echo “$errstr ($errno)<br />\n”;
} else {
$out = “GET /search?client=navclient-auto&ch=” . $ch . “&features=Rank&q=info:” . $url . ” HTTP/1.1\r\n” ;
$out .= “Host: www.google.com\r\n” ;
$out .= “Connection: Close\r\n\r\n” ;
fwrite($fp, $out);
while (!feof($fp)) {
$data = fgets($fp, 128);
$pos = strpos($data, “Rank_”);
if($pos === false){
}else{
$pagerank = substr($data, $pos + 9);
$this->pr_image($pagerank);
}
}
fclose($fp);
}
}
//display pagerank image. Create your own or download images I made for this script. If you make your own make sure to call them pr0.gif, pr1.gif, pr2.gif etc.
function pr_image($pagerank){
if($pagerank == 0){
$this->pr = “<img src=\”images/pr0.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}elseif($pagerank == 1){
$this->pr = “<img src=\”images/pr1.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}elseif($pagerank == 2){
$this->pr = “<img src=\”images/pr2.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}elseif($pagerank == 3){
$this->pr = “<img src=\”images/pr3.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}elseif($pagerank == 4){
$this->pr = “<img src=\”images/pr4.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}elseif($pagerank == 5){
$this->pr = “<img src=\”images/pr5.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}elseif($pagerank == 6){
$this->pr = “<img src=\”images/pr6.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}elseif($pagerank == 7){
$this->pr = “<img src=\”images/pr7.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}elseif($pagerank == 8){
$this->pr = “<img src=\”images/pr8.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}elseif($pagerank == 9){
$this->pr = “<img src=\”images/pr9.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}else{
$this->pr = “<img src=\”images/pr10.gif\” alt=\”PageRank ” .$pagerank. ” out of 10\”>” ;
}
}
function get_pr(){
return $this->pr;
}
}
?>

Do following:

Copy this code anh paste into any place on your website to view on:

<?php
include(”pagerank.php”);
$gpr = new pageRank();
$gpr->printrank(”http://www.yahoo.com”);
//display image
echo $gpr->get_pr();
?>

AddThis Social Bookmark Button

How to change WP excerpt length

March 6th, 2009 Script Posted in Ebooks - Tips, How to No Comments » 55 views

A recent visitor to the WordPress Support Forum asked if is possible to increase the length of excerpts when using the the_excerpt tag. Yes it is. The default value is set to 55. The file that controls this is located at wp-includes/formatting.php. Look for excerpt_length and adjust accordingly.

Having said that altering core files is never a good idea unless you know what you’re doing. A better option to achieve the result is to insert the following in to your theme’s function.php file (if your theme doesn’t have one then create it).

remove_filter(’get_the_excerpt’, ‘wp_trim_excerpt’);
add_filter(’get_the_excerpt’, ‘custom_trim_excerpt’);

function custom_trim_excerpt($text) { // Fakes an excerpt if needed
global $post;
if ( ” == $text ) {
$text = get_the_content(”);
$text = apply_filters(’the_content’, $text);
$text = str_replace(’]]>’, ‘]]>’, $text);
$text = strip_tags($text);
$excerpt_length = x;
$words = explode(’ ‘, $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, ‘…’);
$text = implode(’ ‘, $words);
}
}
return $text;
}

An even easier method is to simply use a plugin from the WordPress Plugin Directory. I haven’t carefully looked through the selection for a plugin that would do this but I’m sure there is at least one.

AddThis Social Bookmark Button

How to disable post revisions

March 6th, 2009 Script Posted in Ebooks - Tips, How to No Comments » 124 views

One of the new features introduced in WordPress 2.6 was a handy little tool called post revisions. In a nutshell this allows you save and track any changes made to a post or page ala Wiki and quickly revert to an earlier version. But what if you are your blog’s only author? What if you simply don’t want this feature?

It wasn’t very long ago the WordPress support forums were filled with threads from people asking how to turn off the feature citing massive growth in the size of the database. While it’s true that a single post can result in oodles of revisions being stored depending on how many times you edit a particular post it’s not a critical issue as space is relatively cheap these days. On the other hand I understand how some people just don’t want the extra clutter. Heck, I’ve even disabled it on this very blog. So then how do we disable post revisions? Using a plain text editor such as Notepad, open up wp-config.php and add the following line …

define (’WP_POST_REVISIONS’, 0);

To keep your copy of wp-config.php neat and orderly a good place to insert this is right after the following lines …

define(’AUTH_KEY’, ‘put your unique phrase here’); // Change this to a unique phrase.
define(’SECURE_AUTH_KEY’, ‘put your unique phrase here’); // Change this to a unique phrase.
define(’LOGGED_IN_KEY’, ‘put your unique phrase here’); // Change this to a unique phrase.

This will turn off post revisions but what about the revisions currently stored in the database? This is also easy to deal with. Login to phpMyAdmin and run the following query …

DELETE FROM wp_posts WHERE post_type = “revision”;

Or an even more comprehensive query which will also delete any categories or custom field values assigned to those revisions …

delete x,y,z
from wp_posts x
left join wp_term_relationships y on (x.id = y.object_id)
left join wp_postmeta z on (x.id = z.post_id)
where x.post_type = ‘revision’

It goes without saying that you should backup your database prior to making any changes to it.

AddThis Social Bookmark Button

Using more on Quicktags

March 6th, 2009 Script Posted in Ebooks - Tips, How to No Comments » 61 views

A visitor to the forums today asked how to add a pullquote to his blog. If you recall, I explained how to do this back in April in a post titled Using Pullquotes Part Two. In that post I showed you not only how to do it but how to do it easily by adding a new quicktag to your post toolbar. This is a mod I use in my own blog. Although I don’t often use pullquotes it’s nice to have the option of clicking a button should I decide to use them. I thought I would share with you the way I added a few additional quicktags.

Being the type that prefers to work with raw HTML I have long since disabled the visual editor. The only drawback to this is the limited number of available quicktags on the toolbar in HTML mode as opposed to visual mode. Since I write quite a few how-tos on this blog I find myself constantly typing in certain HTML character entities over and over. For instance, if I need to display a < character in a post I have to manually type in &lt; or if I need to display a > character I have to manually type in &gt; and so forth. Here is how you can add two extra quicktags to your toolbar so that you can add a < or > to a post with the click of a button.

The file we need to edit is located at wp-includes/js/quicktags.js. Open quicktags.js in a plain text editor such as Notepad. At around Line 60 you’ll see this…

edButtons[edButtons.length] =
new edButton(’ed_block’
,’b-quote’
,’\n\n<blockquote>’
,’</blockquote>\n\n’
,’q’
);

Somewhere below that add the following…

edButtons[edButtons.length] =
new edButton(’ed_<’
,’<’
,’<’
,”
,”
);

edButtons[edButtons.length] =
new edButton(’ed_>’
,’>’
,’>’
,”
,”
);

Since I write a lot of code on this site I’m always using the code quicktag. But I also needed a quicktag for the pre function. Here is how I added that…

Everything I need is a click of the button away. This is what my toolbar looks like. (click to enlarge)

quicktags An important caveat: since you are modifying core files be sure to note your changes for they will vanish the next time you upgrade your WordPress install.

AddThis Social Bookmark Button

Add fun code into single.php

March 6th, 2009 Script Posted in Ebooks - Tips, How to No Comments » 64 views

I’ve used a number of themes on this site in recent times for one reason or another but one thing you can be sure of is I will tweak the heck out of whatever theme I’m using at the moment. Part of the fun of using a new theme is ripping it apart then putting it back together again after having put your own stamp on it.

Some of the things I have done to this theme include creating images pulled from custom fields which are displayed on the home page, building a horizontal navigation menu to display categories and constructing a “more news from this category” module which is shown on single post pages. In this post I’ll show you how to do the latter.

In your favourite plain text editor open the file that generates your sidebar and insert the following …

<?php global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<h3>More News From This Category</h3>
<ul>
<?php
$posts = get_posts(’numberposts=20&category=’. $category->term_id);
foreach($posts as $post) :
?>
<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
<?php endforeach; ?>
<li><strong><a href=”<?php echo get_category_link($category->term_id);?>” title=”View all posts filed under <?php echo $category->name; ?>”>ARCHIVE FOR ‘<?php echo $category->name; ?>’ CATEGORY »</a></strong></li>
<?php endforeach; ?>
</ul>

What this will do is create a list of the 20 most recent posts from whatever category the post currently being displayed on single.php is from. For instance, if you’re reading a post from the Automobile category the sidebar will display the 20 most recent entries from that category complete with a link to the topic archives. Obviously you can change the number of posts you want shown.

As a further enhancement, on this site I created a sidebar to hold this content which is exclusive to single.php. In other words, the sidebar appearing on single post pages will not appear elsewhere on this site.

AddThis Social Bookmark Button