Praktické útržky kódu

Title of the site


<?php bloginfo('name'); ?>

Basic URL of the site


<?php echo site_url(); ?>

<?php echo home_url(); ?>

Exact URL for the site (incl. path)


<?php bloginfo('url'); ?>

Name of the site


<?php bloginfo('name'); ?>

Site’s description


<?php bloginfo('description'); ?>

The style.css style’s location


<?php bloginfo('stylesheet_url'); ?>

The style.css style’s directory


<?php bloginfo('stylesheet_directory'); ?>

Location for the site’s theme files


<?php bloginfo('template_url'); ?>

Title of the specific post or page


<?php wp_title(); ?>
<?php the_title(); ?>

Url of a specific post or page


<?php the_permalink(); ?>

Category of a specific post or page


<?php the_category(', ') ?>

Author of a specific post or page


<?php the_author(); ?>

ID of a specific post or page


<?php the_ID(); ?>

Link to edit a specific post or page


<?php edit_post_link(); ?>

RSS2 URL for the site


<?php bloginfo('rss2_url'); ?>

Content of the posts


<?php the_content(); ?>

Header.php file’s content


<?php get_header(); ?>

Sidebar.php file’s content


<?php get_sidebar(); ?>

Footer.php file’s content


<?php get_footer(); ?>

The date in ’08-18-07′ format


<?php the_time('m-d-y'); ?>

Link for the comments on the post


<?php comments_popup_link(); ?>

Links from the blogroll


<?php get_links_list(); ?>

Comment.php file’s content


<?php comments_template(); ?>

List of pages


<?php wp_list_pages(); ?>

List of categories


<?php wp_list_cats(); ?>

Url to the next post


<?php next_post_link('%link'); ?>

Url to the previous post


<?php previous_post_link('%link'); ?>

The built-in calendar


<?php get_calendar(); ?>

List of archives for the site


<?php wp_get_archives(); ?>

Next and previous post link


<?php posts_nav_link(); ?>

Include any file


<?php include(TEMPLATEPATH . '/x'); ?>

Value for search form


<?php the_search_query(); ?>

Prints out message


<?php _e(’Message’); ?>

Displays the register link


<?php wp_register(); ?>

Displays the login/logout link


<?php wp_loginout(); ?>

Divides the content into pages


<!--next page-->

Cuts off the content and adds a link to the rest of the content


<span id="more-767"></span>

This snippet will include the file specified, only if the user is on the home page of the site


<?php if (is_home()) { include ('example.php'); } ?>

Styling Difierent Categories

This snippet assigns a specific stylesheet (category-15.css) to category 15 and will assign the rest of the site the default stylesheet (style.css). Place this code in the area.


<?php if ( is_category('15') ) {
  <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/cat-15.css" 
type="text/css" media="screen" />;
<?php } else { ?>
   <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" 
type="text/css" media="screen" />
<?php } ?>

Unique Images For Difierent Categories
This snippet assigns an image (cat7.jpg) next to each post title in category 7 and an image (cat8.jpg) next to each post title in category 8. Place this code in the category.php file.


<?php if (is_category('7') ):
 <img src='<?php bloginfo('template_url');?>/images/cat7.jpg' alt='' />
<?php } elseif (is_category('8') ):
 <img src='<?php bloginfo('template_url');?>/images/cat8.jpg' alt='' />
<?php endif; ?>

Styling Individual Posts

This snippet will assign the post ID to the DIV. For example, if the ID for the post is 8, that line will echo as

. Now you can style that individual post in the CSS as #post-8. Place this code within the loop.


<div id="post-<?php the_ID(); ?>">

Query Posts
This snippet will display the 5 latest posts from only category 2. Place this code right before the loop.


<?php query_posts('cat=2&showposts=5'); ?>

Tags Cloud
This snippet will create a tag cloud, in alphabetical order, with the smallest text at 1 pt and the largest text at 9 pts.


<?php wp_tag_cloud('smallest=1&largest=9&'); ?>

Unique Templates For Categories


<?php
 $post = $wp_query- >post;
 if (in_category('3')) {
 include(TEMPLATEPATH . '/cat3.php');
 } elseif (in_category('4')) {
 include(TEMPLATEPATH . '/cat4.php');
 } else {
 include(TEMPLATEPATH . '/cat.php');
 } ?>