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>

Posted in WordPress. Comments Off on Add Random Posts in a Page »

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 your wordpress homepage, you blog will looks more great.

if you change numberposts=10 to -1, it will show all posts under the category.

Posted in WordPress. Comments Off on Get certain number posts »

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
$start = "1"; //which image you want to load first
$random = mt_rand($start, $total);
$image_name = $random . $file_type;
echo "\";

Posted in Php Code. Comments Off on PHP image link rotation »

How to use htaccess to change site.com/directory/ to site.com/ ?

If you only want http://kingphp.com/money directory become http://kingphp.com, use:RewriteRule ^catalog/$ / [L]

If you want all directories become http://kingphp.com, 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 files from catalog/ subfolder to your main url.

Posted in Apache. Comments Off on How to use htaccess to change site.com/directory/ to site.com/ ? »

How to use mod rewrite forward to a new domain?

For examples, when we visit www.google.com, we want it redirect to http://kingphp.com, we can use the following code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

The code posted above should be used on the old server.

Posted in Apache. Comments Off on How to use mod rewrite forward to a new domain? »

How to redirect folders (and all the link)

For example, if we want to redirct http://kingphp.com/php/ to http://kingphp.com/wordpress/

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]

Posted in Apache. Comments Off on How to redirect folders (and all the link) »

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 domain1.com to folder1
ReWriteCond %{HTTP_HOST} domain1.com
ReWriteCond %{REQUEST_URI} !folder1/
ReWriteRule ^(.*)$ folder1/$1 [L]

# pointing for the domain domain2.com to folder2
ReWriteCond %{HTTP_HOST} domain2.com
ReWriteCond %{REQUEST_URI} !folder2/
ReWriteRule ^(.*)$ folder2/$1 [L]

Posted in Apache. Comments Off on Using .htaccess pointing domain to specific directory »

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. (more…)

Posted in Apache, WordPress. Comments Off on WordPress Permalinks Does Not Work in xampp Setup »

.htaccess redirect ALL traffic to another domain

.htaccess code:
redirect 302 / http://www.mynewdomain.com

you can also redirect access via PHP, using the header() function:

// Permanent redirect:
header('HTTP/1.1 301 Moved Permanently', true);
header('Location: http://www.location.com/');
// Temporary redirect (note that sending the 'Location' header automatically sends a 302 redirect unless it is explicitly overwritten, as it is above):
header('Location: http://www.location.com/');

Posted in Apache, Php Code. Comments Off on .htaccess redirect ALL traffic to another domain »

No Sidebars Defined

This should work. In sidebar.php, add this just after the first < ul > :

Add this just before the last < /ul > :

Now create a new, blank page in your editor and save it as functions.php . Place this on the new functions.php page:

Upload functions.php and sidebar.php to the theme folder. Your sidebar should now be widgetized.

Posted in WordPress. Comments Off on No Sidebars Defined »
King Php Science Designed by:KingPhp.com Welcome, you are from: 54.146.11.8