frequently used wordpress tags
STYLE.CSS HEADER
/* Theme Name: My Site name Description: an awesome theme that I built Author: Your name Author URI: http://www.yoursite.com */
HEADER STUFF
head tags
<html <?php language_attributes(); ?>> <meta charset="<?php bloginfo( 'charset' ); ?>" />
<title> <?php /* * Print the <title> tag based on what is being viewed. * We filter the output of wp_title() a bit -- see * twentyten_filter_wp_title() in functions.php. */ wp_title( '|', true, 'right' );?> </title> <link rel="profile" href="http://gmpg.org/xfn/11" /> <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /> <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" /> <?php /* Always have wp_head() just before the closing </head> * tag of your theme, or you will break many plugins, which * generally use this hook to add elements to <head> such * as styles, scripts, and meta tags. */ wp_head(); ?>
BODY
<body <?php body_class(); ?>>
Page content– THE LOOP
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <h1><?php the_title(); ?></h1> <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?> <?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?> <?php //comments_template( '', true ); ?> <?php endwhile; ?>
NAV MENU
<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>
SIDEBAR
<div> <ul class="widgets"> <?php dynamic_sidebar( 'primary-widget-area' ) ?> </ul> </div>
FOOTER
<?php /* Always have wp_footer() just before the closing </body> * tag of your theme, or you will break many plugins, which * generally use this hook to reference JavaScript files. */ wp_footer(); ?>
OTHER USEFUL STUFF
insert post thumbnail
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('large'); } ?> or give it a class of 'alignleft'... <?php the_post_thumbnail('medium', array('class' => 'alignleft'));?>
insert custom field
<?php echo get_post_meta($post->ID, 'right_box', true); ?>
add a second loop to a page
<?php //this is a separate query loop that grabs the 3 most recent posts of the category with ID of 12. $blogquery = new WP_Query( 'cat=12&posts_per_page=3' ); // The Loop while ( $blogquery->have_posts() ) : $blogquery->the_post(); ?> <div> <h3><?php the_title();?></h3> <?php the_excerpt(); ?> </div> <?php endwhile; // Reset Post Data wp_reset_postdata(); ?>
Named Page Template
<?php /* Template Name: Templat Name // the line of code above is what makes wordpress recognize this as a template. When editing a page, it will appear as a Page Template in the "page attributes" box. */ ?>
Insert a link to the post that you are listing (such as on the main blog list)
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
create an absolute link to a file that will not break when you migrate the site.
<a href="<?php bloginfo( 'stylesheet_directory' ); ?>/image.jpg">link text </a>
Want more in-depth training on this topic? Schedule a one-on-one training session!