Show post titles at category, and show your own words at homepage.

<?php get_header(); ?>

<?php if (is_home())

echo ”
Welcome, add your own words here!

“; ?>

<?php if (!is_home())

{ ?>
<ul>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href=”<?php echo get_permalink()?>”><?php the_title(); ?></a>
</li>
<?php endwhile; endif; ?>
<ul>

<?php }  ?>

<?php get_footer(); ?>

Posted in Php Skills, WordPress. Comments Off on Show post titles at category, and show your own words at homepage. »

How show wordpres categories?

Method a:

wp_list_categories().

Usage
 <?php wp_list_cats(‘arguments’); ?> 

Examples
Default Usage
By default, the tag:

optionall – Does not display a link to all Categories
all – Text to display for link to all Categories
sort_column – Sorts by Category ID
sort_order – Sorts in ascending order
file – Displays the Categories using the index.php template
list – Sets the Categories in an unordered list (<ul><li>)
optioncount – Does not display the count of posts within each Category
hide_empty – Does not display links to Categories which have no posts
use_desc_for_title – Uses the Category description as the link title
children – Shows the children (sub-Categories) of every Category listed
hierarchical – Displays the children Categories in a hierarchical order under its Category parent (more…)

Posted in WordPress. Comments Off on How show wordpres categories? »

Increase the memory-limit in php

When you run wordpress under xamm,
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 334230 bytes) in D:\xampp\htdocs\test.php on line814.

 1. Open \xampp\apache\bin\php.ini .Do not go to the directory of phpt to find php5.ini .
2. Search”memory” and get the following:

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 60     ; Maximum execution time of each script, in seconds
max_input_time = 60    ; Maximum amount of time each script may spend parsing request data
memory_limit = 32M      ; Maximum amount of memory a script may consume (16MB)

3. Modify the value of “memory_limit =” ,usuall change it to 64M.

4. Reboot Apache.

Posted in Apache, Php Functions, WordPress. Comments Off on Increase the memory-limit in php »

How to add ads only at the first post?

It is very simple:

<?php if ($wp_query->current_post == 0) : ?>

<div style=”float:right”>

ads come here.

</div>
<?php endif; ?>

If you don’t want the ads show at homepage, using:

<?php if (!is_home()) ?>

Posted in Php Code, WordPress. Comments Off on How to add ads only at the first post? »

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;
}

Posted in Php Skills, WordPress. Comments Off on How to let tag cloud show the same size font and in list style? »

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();–>

Posted in WordPress. Comments Off on How to let the post show from lowest to highest? »

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

Posted in Php Code, WordPress. Comments Off on List 50 posts of wordpress. »

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

Posted in WordPress. Comments Off on WordPress Random posts »

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
?>

Posted in Php Code, WordPress. Comments Off on Retrieve a Particular Post or Page »

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 »
King Php Science Welcome, you are from: 54.146.11.8