PHP Code for WordPress

Grab Category Name

This PHP snippet will get the category of the current post and place it in line where the code is inserted. It would be useful to add a heading or phrase that relates to the category.

<? $cat = get_the_category(); $cat = $cat[0]; echo $cat->cat_name;?>

PHP Snippets for Header
<?php bloginfo(‘name’); ?> Title of the site
<?php wp_title(); ?> Title of the specific post or page
<?php bloginfo(‘stylesheet_url’); ?> The style.css file’s location
<?php bloginfo(‘pingback_url’); ?> Pingback URL for the site
<?php bloginfo(‘template_url’); ?> Location for the site’s theme files
<?php bloginfo(‘version’); ?> WordPress version for the site
<?php bloginfo(‘atom_url’); ?> Atom URL for the site
<?php bloginfo(‘rss2_url’); ?> RSS2 URL for the site
<?php bloginfo(‘url’); ?> Exact URL for the site
<?php bloginfo(‘name’); ?> Name of the site
<?php bloginfo(‘html_type’); ?> HTML version of the site
<?php bloginfo(‘charset’); ?> Charset parameter of the site
PHP Snippets for Templates
<?php the_content(); ?> Content of the posts
<?php if(have_posts()) : ?> Checks if there are posts
<?php while(have_posts()) : the_post(); ?> Shows posts if posts are available
<?php endwhile; ?> Closes the ‘while’ PHP function
<?php endif; ?> Closes the ‘if’ PHP function
<?php get_header(); ?> Header.php file’s content
<?php get_sidebar(); ?> Sidebar.php file’s content
<?php get_footer(); ?> Footer.php file’s content
<?php the_time(‘m-d-y’) ?> The date in ’08-18-07′ format
<?php comments_popup_link(); ?> Link for the comments on the post
<?php the_title(); ?> Title of a specific post or page
<?php the_permalink() ?> Url of a specific post or page
<?php the_category(‘, ‘) ?> Category of a specific post or page
<?php the_author(); ?> Author of a specific post or page
<?php the_ID(); ?> ID of a specific post or page
<?php edit_post_link(); ?> Link to edit a specific post or page
<?php get_links_list(); ?> Links from the blogroll
<?php comments_template(); ?> Comment.php file’s content
<?php wp_list_pages(); ?> List of pages of the
<?php wp_list_cats(); ?> List of categories for the site
<?php next_post_link(‘ %link ‘) ?> Url to the next post
<?php previous_post_link(‘%link’) ?> Url to the previous post
<?php get_calendar(); ?> The built-in calendar
<?php wp_get_archives() ?> List of archives for the site
<?php posts_nav_link(); ?> Next and previous post link
<?php bloginfo(’description’); ?> Site’s description

2 Responses to “PHP Code for WordPress”

  1. theresa Says:


    Thank you for posting information to be used for making minor changes to the php in word press themes.

    What would you recommend for on-line learning to better code changes to the php? My programming background is in PeopleTools, SQL and RPG.


  2. amitmondal Says:

    Nice post….thanks
    Please visit this blog for learn more PHP scripts….

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: