Retrieve a Particular Post or Page

Retrieve a Particular Post <?php // retrieve one post with an ID of 5 query_posts(‘p=5’);      ?> If you want to use the Read More functionality with this query, you will need to set the global $more variable to 0. <?php // retrieve one post with an ID of 5 query_posts(‘p=5’);       global $more; // set […]

Add Random Posts in a Page

get_posts() can be used to collect and display any number of random posts you want. Here’s an example that lists the titles (as links) of four random posts: <ul><li><h2>Some Random Posts</h2> <ul> <?php $rand_posts = get_posts(‘numberposts=4&orderby=RAND()’); foreach( $rand_posts as $post ) : ?> <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> </li></ul>

Get certain number posts

<?php $posts = get_posts( “category=1&numberposts=10″ ); ?> <?php if( $posts ) : ?> <ul><?php foreach( $posts as $post ) : setup_postdata( $post ); ?> <li> <a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></a> </li> <?php endforeach; ?> </ul> <?php endif; ?>   category=1&numberposts=10, means category 1, and list 10 posts add the code at […]

PHP image link rotation

The script is for my vbulletin forum in PHP which we can stick our affiliate banners with their links so that they rotate on refresh. The code is as follows: $total = “6”; //6 – change to how many images you have $file_type = “.jpg”; //change to file type $image_folder = “random”; //location of folder […]

How to use htaccess to change to ?

If you only want directory become, use:RewriteRule ^catalog/$ / [L] If you want all directories become, use: RewriteEngine On RewriteBase / RewriteRule ^([^/]+)$ /catalog/$1 [L] RewriteRule ^$ /catalog/ [L] Note:If you have other subfolders in there (in that catalog dir, you’ll need some additional rule for that also. This will rewrite your […]

How to use mod rewrite forward to a new domain?

For examples, when we visit, we want it redirect to, we can use the following code: Options +FollowSymLinks RewriteEngine on RewriteRule (.*)$1 [R=301,L] The code posted above should be used on the old server.

How to redirect folders (and all the link)

For example, if we want to redirct to We could use mod_rewrite. Put this in your .htaccess file Options +FollowSymLinks RewriteEngine On RewriteRule /php/(\w+).html /wordpress/$1.html [R=301,L]

Using .htaccess pointing domain to specific directory

If a server hosting 2 domains, we can use this .htaccess (on the root) to point the 2 different domains to 2 Directories on the same server: RewriteEngine On RewriteBase / # pointing for the domain to folder1 ReWriteCond %{HTTP_HOST} ReWriteCond %{REQUEST_URI} !folder1/ ReWriteRule ^(.*)$ folder1/$1 [L] # pointing for the domain […]

WordPress Permalinks Does Not Work in xampp Setup

xampp provides a convenient way to quickly and easily install and setup a web server that works without much configuration. However, permalinks feature won’t work with the default installation of xampp, even though you can properly customize the permalinks structure to create the .htaccess file.

.htaccess redirect ALL traffic to another domain

.htaccess code: redirect 302 / you can also redirect access via PHP, using the header() function: // Permanent redirect: header(‘HTTP/1.1 301 Moved Permanently’, true); header(‘Location:’); // Temporary redirect (note that sending the ‘Location’ header automatically sends a 302 redirect unless it is explicitly overwritten, as it is above): header(‘Location:’);