Get the HREF:
<?php bloginfo('url'); ?>
Get the Site Name
<?php bloginfo('name'); ?></a>
Wrap Link to Home Around the Site Name
<a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a>
This provides the link from the header.php file to the main stylesheet » usually style.css.
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" media="screen, projection" />
This is necessary when linking from the header.php file to stylesheets, javascript files, etc.
The HREF to the stylesheet directory
<?php bloginfo('stylesheet_directory'); ?>
Sample link to a print stylesheet
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/assets/css/print.css" media="print" />
Sample link to a jQuery file
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/assets/js/jquery.js"></script>
NOTE: This provides a dynamically generated title that references the specific page or post.
<title>
<?php if (is_home()) { echo bloginfo('name');
} elseif (is_404()) {
echo '404 Not Found » '; bloginfo('name');
} elseif (is_category()) {
echo wp_title(' » ',true,'right'); bloginfo('name');
} elseif (is_search()) {
echo 'Search Results » '; bloginfo('name');
} elseif ( is_day() || is_month() || is_year() ) {
echo wp_title(' » ',true,'right'); bloginfo('name');
} else {
echo wp_title(' » ',true,'right'); bloginfo('name');
}
?>
</title>
Here's an example of what an entire head section of the header.php file might look like.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>><head profile="http://gmpg.org/xfn/11">
<title>
<?php if (is_home()) { echo bloginfo('name');
} elseif (is_404()) {
echo '404 Not Found » '; bloginfo('name');
} elseif (is_category()) {
echo wp_title(' » ',true,'right'); bloginfo('name');
} elseif (is_search()) {
echo 'Search Results » '; bloginfo('name');
} elseif ( is_day() || is_month() || is_year() ) {
echo wp_title(' » ',true,'right'); bloginfo('name');
} else {
echo wp_title(' » ',true,'right'); bloginfo('name');
}
?>
</title><meta http-equiv="content-type" content="<?php bloginfo('html_type') ?>; charset=<?php bloginfo('charset') ?>" />
<meta name="description" content="<?php bloginfo('description') ?>" />
<?php if(is_search()) { ?>
<meta name="robots" content="noindex, nofollow" />
<?php }?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" media="screen, projection" /><!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/assets/css/ie7.css" media="screen" />
<![endif]--><!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/assets/css/ie6.css" media="screen" />
<![endif]--><!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/assets/css/ielt6.css" media="screen" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/assets/css/print.css" media="print" />
<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /><script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/assets/js/jquery/js/jquery.js"></script>
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/assets/js/jquery/js/jquery-custom.js"></script>
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/assets/js/jquery.js"></script></head>
Nav with links to Home and Pages, auto-generated
NOTE: also adds class "current" to the current page
<div id="nav">
<ul>
<li<?php
if (is_home())
{
echo " class=\"current_page_item\"";
}?>><a href="<?php bloginfo('url'); ?>">Home</a></li>
<?php wp_list_pages('title_li=&depth=0'); ?>
</ul>
</div><!-- closes nav div -->
"The Loop" is the set of PHP and HTML tags that pulls the post or page content out of the database to display in the page.
It typically includes:
Here is what a typical loop might look like:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<p class="postinfo"><?php the_time('F jS, Y') ?> by <?php the_author() ?> </p>
<?php the_excerpt('Read the rest of this entry »'); ?>
<p><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
<?php endwhile; ?>
<ul class="post_nextprev">
<li><?php next_posts_link('« Older Entries') ?></li>
<li><?php previous_posts_link('Newer Entries »') ?></li>
</ul>
<?php else : ?>
<h2>Not Found</h2>
<p>Sorry, but you are looking for something that isn't here.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>
Enables you to get a set number of posts from a certain category and display the title, excerpt, and link to the post.
<?php
$myposts = get_posts('numberposts=10&category=15');
foreach($myposts as $post) : ?> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3> <p><?php the_excerpt('Read the rest of this story »'); ?></p> <?php endforeach; ?>
Get custom field information belonging to a post.
<?=get_post_meta($post->ID, 'FlickrImageURL', true)?>
For more information on this topic, see: "Custom Fields" at the WordPress Codex.
Code for displaying name and link to parent categories, followed by current category:
<?php echo(get_category_parents($cat, TRUE, ' » ')); ?>Code for displaying name and link to parent page, followed by current page:
Link to next or previous posts:
Include an RSS feed from any source. Line one includes the necessary function from the WordPress core. Line two includes the URL of the feed, followed by the number of RSS entries you want to display.
<?php include_once(ABSPATH.WPINC.'/rss.php');
wp_rss('http://feeds.feedburner.com/wprecipes', 3); ?>
This a little experiment thrown together to be used for class presentations.
Eventually this will enable me to use the same markup for course resource pages and -- with a click of a button -- for in-class presentations.
Right now, this is the experimental first version of the in-class presentation format.
Obviously, with work still remaining to be done!
If you have questions or suggestions, tweet me.