Blog

Archive for the ‘Snippets’ Category

wordpress

Working with WordPress child themes: Including files and getting the theme path

Saturday, October 30th, 2010

Recently I have been creating child themes in wordpress and It turns out that we cant use TEMPLATEPATH for including files and template_directory for getting the full theme directory path. These reference the actual parent theme. We need to use stylesheet_directory and STYLESHEETPATH.

Here are two examples we would use when dealing with child themes:

<?php include (STYLESHEETPATH . ‘/includes/pageheader.php’); ?>

<script src=”<?php echo bloginfo(‘stylesheet_directory’); ?>/js/modernizr-1.5.min.js”></script>

References:

wordpress

How to create a sidebar navigation in WordPress

Wednesday, February 3rd, 2010

Here’s a snippet that will give you an instant sidebar navigation in WordPress. It grabs the post parent title and the children of that parent.

<div id="sidebar-nav">
< ?php if($post->post_parent) { ?>
< ?php $parent_title = get_the_title($post->post_parent); ?>
< ?php $permalink = get_permalink($post->post_parent); ?>
<h3><a href="<?php echo $permalink; ?>" title="< ?php echo $parent_title; ?>">< ?php echo $parent_title; ?></a></h3>
 < ?php } else { ?>
<h3><a href="<?php echo get_permalink(); ?>" title="< ?php echo $parent_title; ?>">< ?php the_title(); ?></a></h3>
< ?php } ?> 
 
< ?php
if($post->post_parent) {
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); 
}
else {
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); 
}
if ($children) { ?> 
<ul>
< ?php echo $children; ?>
</ul>
< ?php } ?>
</div>

Linking to Google’s Hosted jQuery Repository

Sunday, November 30th, 2008

jQuery Hosted on Google:

Here’s the code to link to Google’s jQuery repository. It grabs the latest jQuery version.

<script src="http://code.jquery.com/jquery-latest.js"></script>

If you want to target a particular version of jquery:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

Google link to jQuery:

You can go here http://code.google.com/p/jqueryjs/downloads/list for the download list and right-click copy-link location.

Jquery CDNs

Go to http://docs.jquery.com/Downloading_jQuery for a list of CDNs

 

Updated: 6/14/11 12:22pm