Category Archives: Web design/Coding

Limit the number of sticky posts appearing on site

Code to limit the number of sticky posts shown in a page

/* Get all sticky posts */
$sticky = get_option( ‘sticky_posts’ );

/* Sort the stickies with the newest ones at the top */
rsort( $sticky );

/* Get the 2 newest stickies (change 5 for a different number) */
$sticky = array_slice( $sticky, 0, 5 );

/* Query sticky posts */
query_posts( array( ‘post__in’ => $sticky, ‘caller_get_posts’ => 1 ) );

Using 301 Redirect To Redirect A Webpage

When I hosted the site, the pages were html files. Later to add more functionality I converted them to php files.

But search engines have already indexed those .html files. So when a visitor comes after a search in Google, the ‘ File Not Found’ error is displayed.

We can avoid this using 301 redirect.

.htaccess file
When a visitor searches for a webpage, the webserver looks for .htaccess file. This file contains information about redirection, security etc.

If your server already has this file always update it rather than replacing it with a new file.

If the server does not have the .htaccess file open a .txt file and save it as .htaccess file.

Redirect a webpage using 301 Redirect
Example :

redirect 301 /Kids.html

Edit the .htaccess file or open notepad, add redirect 301 statement, save it as .htaccess file.

The search engines won’t read the .htaccess file, but follow the rules that are created in .htaccess.

We can test this by typing the old URL, for example

Actually this file is not in the server. Instead kids.php is there.

When Google updates it next time, the new file name will replace the old file.