How to let tag cloud show the same size font and in list style?

It is very easy to tag cloud show the same size font and in list style, there are 2 ways to do this:

 1. Change sidebar.php in templates:

<li>

<h2>Tag Cloud</h2>

<?php wp_tag_cloud(’smallest=8&largest=8&number=45&orderby=name&format=list’); ?>  <!– wp_tag_cloud(’smallest=8&largest=8&number=45&orderby=name&format=list’)–>
</li>

another way is change code in widgets.php inside include document:

function wp_widget_tag_cloud($args) {
 extract($args);
 $options = get_option(’widget_tag_cloud’);
 $title = empty($options[’title’]) ? __(’Tags’) : apply_filters(’widget_title’, $options[’title’]);

 echo $before_widget;
 echo $before_title . $title . $after_title;
 wp_tag_cloud(”); //wp_tag_cloud(’smallest=8&largest=8&number=45&orderby=name&format=list’);
 echo $after_widget;
}

How to let the post show from lowest to highest?

If you want your posts show from lowest to highest, it is very simple, just add:
<!–p query_posts($query_string.’&order=ASC’);–>

for example, the following code will let all your post show from lowest to highest:

<!–p query_posts($query_string.’&order=ASC’);–>
<!–p if (have_posts()) : while (have_posts()) : the_post();–>

List 50 posts of wordpress.

If you want to list 50 posts, use the following code:

<ul>
 <?php
 global $post;
 $myposts = get_posts(’numberposts=-1′);
 foreach($myposts as $post) :
 ?>
    <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
 <?php endforeach; ?>
 </ul>

if you want to list all the posts, use the following codes:

<ul>
 <?php
 global $post;
 $myposts = get_posts(’numberposts=5′);
 foreach($myposts as $post) :
 ?>
    <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
 <?php endforeach; ?>
 </ul>

http://codex.wordpress.org/Template_Tags/get_posts

Wordpress Random posts

Display a list of 15 posts selected randomly by using the MySQL RAND() function for the orderby parameter value:

 <ul><li><h2>A random selection of kingphp posts</h2>
    <ul>
 <?php
 $rand_posts = get_posts(’numberposts=15&orderby=rand’);
 foreach( $rand_posts as $post ) :
 ?>
    <li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>
 <?php endforeach; ?>
    </ul>
 </li></ul>

 more: http://codex.wordpress.org/Template_Tags/get_posts#Random_posts

How to get root dirctory by php

<?php echo realpath(’./’)?>

very simple, right?

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 $more to 0 in order to only get the first part of the post
$more = 0;

// the Loop
while (have_posts()) : the_post();
  // the content of the post
  the_content(’Read the full post »’);
endwhile;
?>
Retrieve a Particular Page
To retrieve a particular page, you could use the following:

<?php
query_posts(’page_id=7′);      //retrieves page 7 only
?>

or

<?php
query_posts(’pagename=about’); //retrieves the about page only
?>

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

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

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 “\“;

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.