Skip to content

Instantly share code, notes, and snippets.

@zachbrowne
Created May 1, 2012 20:44
Show Gist options
  • Save zachbrowne/2571214 to your computer and use it in GitHub Desktop.
Save zachbrowne/2571214 to your computer and use it in GitHub Desktop.
zachbrowne.com Core custom_functions.php File for Thesis on WordPress
<?php
/**********************************************
*** Contents of custom_functions.php file. ***
**********************************************
* 1. favicon *
* 2. menu *
* 3. remove sidebar on single posts *
* 4. bylines with the 'author' microformat*
* 5. adds continue reading *
* 6. exclude categories from front page *
* 7. smart 404 *
* 8. custom archive page *
* 9. footer widgets *
* 10. twitter timeline *
* 11. footer *
**********************************************/
/*---:[ 1. favicon }:---*/
function site_favicon() { ?>
<link rel="shortcut icon" href="<?php site_url(); ?>/favicon.ico" />
<?php }
add_action('wp_head', 'site_favicon');
/*---:[ 2. menu }:---*/
remove_action('thesis_hook_before_header', 'thesis_nav_menu');
function full_width_nav() { ?>
<div id="nav_area" class="full_width">
<div class="page">
<?php thesis_nav_menu(); ?>
</div>
</div>
<?php }
add_action('thesis_hook_before_content_area', 'full_width_nav');
/*---:[ 3. remove sidebar on single posts }:---*/
function no_sidebars() {
if (is_single())
return false;
else
return true;
}
add_filter('thesis_show_sidebars', 'no_sidebars');
/*---:[ 4. bylines with the 'author' microformat ]:----*/
function custom_headline_catcher() {
ob_start();
}
function custom_headline_catcher_end() {
global $thesis_design;
if ($thesis_design->display['byline']['author']['nofollow'])
$output = str_replace( 'rel="nofollow"', 'rel="nofollow author"', ob_get_contents() );
else
$output = str_replace( 'class="url fn"', 'class="url fn" rel="author"', ob_get_contents() );
ob_end_clean();
echo $output;
}
add_action( 'thesis_hook_post_box_top', 'custom_headline_catcher' );
add_action( 'thesis_hook_before_post' , 'custom_headline_catcher_end' );
/*----:[ 5. adds continue reading ]:----*/
function archive_read_more() {
if (is_home() || is_front_page() || is_archive()) { ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">Continue Reading</a></p>
<?php }
}
add_action('thesis_hook_after_post', 'archive_read_more');
remove_action('thesis_hook_after_post', 'thesis_comments_link');
/*----:{ 6. exclude categories from front page }:----*/
function exclude_cat($query) {
if ( $query->is_home) {
$query-> set('cat','-640');
}
return $query; }
add_filter('pre_get_posts','exclude_cat');
/*----:{ 7. smart 404 }:----*/
function custom_thesis_404_title() { ?>
<h2>Oh No! Looks like there's been an accident.</h2>
<?php }
add_action('thesis_hook_404_title', 'custom_thesis_404_title');
add_action('thesis_hook_404_content', 'custom_thesis_404_content');
function custom_thesis_404_content() { ?>
<p><img src="http://zachbrowne-com-javascript-hosting.googlecode.com/files/3926380916_1837dedf0b.jpg" title="Wrong Turn" target="_blank"></p>
<p>I'll get you back on the road as fast as I can.</p>
<p>Meanwhile, try doing one of the following:</p>
<ul>
<li>Refresh the page. The error may be temporary.</li>
<li>Use the back button to get back to where you were.</li> </ul>
<?php if (smart404_loop()) : ?>
<p>Or try one of these posts instead:</p>
<?php while (have_posts()) : the_post(); ?>
<h4><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"> <?php the_title(); ?></a></h4>
<small><?php the_excerpt(); ?></small>
<?php endwhile; ?>
<?php endif; ?>
<p>You can also just go to my <a href="http://zachbrowne.com/">home page</a>.</p>
<?php }
remove_action('thesis_hook_404_title', 'thesis_404_title');
remove_action('thesis_hook_404_content', 'thesis_404_content');
/*---:[ 8. custom archive page ]:---*/
function category() {
thesis_archive_intro();
echo "<div class=\"post_box top\">\n";
echo "\t<div class=\"format_text\">\n";
echo "\t\t<ul>\n";
while (have_posts()) {
the_post();
echo "\t\t\t<li><a href=\"" . get_permalink() . "\">" . get_the_title() . "</a></li>\n";
}
echo "\t\t</ul>\n";
echo "\t</div>\n";
echo "</div>\n";
}
/*---:[ 9. footer widgets ]:---*/
function footer_widgets() { ?>
<div id="footer_widget_area" class="full_width">
<div class="page">
<div id="footer_widgets">
<div class="col footer1">
<ul class="footer_list">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer 1') ){ ?>
<li class="widget">
<div class="widget_box">
<h3><?php _e('Footer Widget 1', 'thesis'); ?></h3>
<p>You can edit the content that appears here by visiting your Widgets panel and
modifying the <em>current widgets</em> there. <br /><br />Lorem ipsum no has veniam elaboraret constituam, ne nibh posidonium vel. Has ad quaeque omittantur, malis abhorreant eam no, qui cu minim placerat definitionem.</p>
</div>
</li>
<?php } ?>
</ul>
</div>
<div class="col footer2">
<ul class="footer_list">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer 2') ) { ?>
<li class="widget">
<div class="widget_box">
<h3><?php _e('Footer Widget 2', 'thesis'); ?></h3>
<p>You can edit the content that appears here by visiting your Widgets panel and
modifying the <em>current widgets</em> there. <br /><br />Lorem ipsum no has veniam elaboraret constituam, ne nibh posidonium vel. Has ad quaeque omittantur, malis abhorreant eam no, qui cu minim placerat definitionem.</p>
</div>
</li>
<?php } ?>
</ul>
</div>
<div class="col footer3">
<ul class="footer_list">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer 3') ) { ?>
<li class="widget">
<div class="widget_box">
<h3><?php _e('Footer Widget 3', 'thesis'); ?></h3>
<p>You can edit the content that appears here by visiting your Widgets panel and
modifying the <em>current widgets</em> there. <br /><br />Lorem ipsum no has veniam elaboraret constituam, ne nibh posidonium vel. Has ad quaeque omittantur, malis abhorreant eam no, qui cu minim placerat definitionem.</p>
</div>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
</div>
<?php }
register_sidebars(3, array('name'=>'Footer %d', 'before_title'=>'<h3>', 'after_title'=>'</h3>'));
add_action('thesis_hook_after_content_area','footer_widgets');
/*----:[ 10. twitter timeline ]:----*/
function footer_scripts() { ?>
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/zachbrowne.json?callback=twitterCallback2&count=1"></script>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<?php }
add_action('thesis_hook_after_html', 'footer_scripts');
function twitter_widget() { ?>
<li class="widget">
<div id="twitter_div"><ul id="twitter_update_list"><li>&nbsp;</li></ul><img src="<?php bloginfo('template_url'); ?>/custom/images/twitter.png" alt="" /></div>
<p><span class="bracket"><a href="https://twitter.com/ZachBrowne" class="twitter-follow-button" data-show-count="true">Follow @ZachBrowne</a>
</span></p>
</li>
<?php }
add_action('thesis_hook_before_sidebar_1', 'twitter_widget');
/*----:[ 11. footer ]:----*/
function footer_copy() { ?>
<p>Copyright &copy; 2011, Zach Browne. All rights reserved. | <a href="/privacy-policy/" rel="nofollow">Privacy Policy</a> : <a href="/terms-of-service/" rel="nofollow">Terms of Service</a> : <a href="/site-map">Site Map</a><br />Hosted proudly with <a href="http://www.linode.com" rel="nofollow">Linode</a> on the WordPress <a href="http://www.diythemes.com" rel="nofollow">Thesis</a> framework using <a href="http://www.gravityforms.com" rel="nofollow">Gravity Forms</a> and <a href="http://www.windowsazure.com" rel="nofollow">Windows Azure</a> for a CDN.</p>
<?php }
add_action('thesis_hook_footer', 'footer_copy');
remove_action('thesis_hook_footer', 'thesis_attribution');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment