All · Bootstrap · Google Analytics · Sage · Uncategorised · Wordpress

Use default thumbnail if no featured image

<?php if ( has_post_thumbnail() ) { ?>
 <?php the_post_thumbnail('thumbnail'); ?>
<?php } else { ?>
<img width="150" height="150" alt="post-thumb" class="attachment-thumbnail wp-post-image" src="<?php echo get_stylesheet_directory_uri(); ?>/assets/img/default-thumb.jpg">
 <?php }; ?>

Multi except lengths

//change excerpt length
 add_filter('excerpt_length', 'my_excerpt_length');
 function my_excerpt_length($length) {
 if (is_home()){
 return 25;
 }
 else {
 return 50;
 }
 }

Echo site URL

<?php echo get_site_url(); ?>

Get parent page title

<?php
 $parent_title = get_the_title($post->post_parent);
 echo $parent_title;
 ?>

Add onload tag function

add_filter('template_include','my_places_add_to_body_load',1);
 function my_places_add_to_body_load($template) {
 if ( is_page(array ('store-results' ) ) ) {
 ob_start('myplaces_load_js');  // Start Page Buffer
 }
 return $template;
 }
 function myplaces_load_js($buffer) {
 return str_replace('<body','<body onload="load()"',$buffer);
 }

Useful WordPress tutorials and resources

Tutorials

WordPress theme tutorial:
http://code.tutsplus.com/series/making-the-perfect-wordpress-theme–wp-33987

Guide to custom post types (required for almost every site):
http://www.smashingmagazine.com/2012/11/08/complete-guide-custom-post-types/
http://blog.teamtreehouse.com/create-your-first-wordpress-custom-post-type
http://code.tutsplus.com/tutorials/a-guide-to-wordpress-custom-post-types-taxonomies-admin-columns-filters-and-archives–wp-27898

Featured images:
http://voodoopress.com/woking-with-featured-image-in-wordpress/

Custom post image slider:
http://bluelimemedia.com/2012/03/01/build-a-custom-image-slider-using-a-custom-post-type/

Portfolio Tutorial:
http://code.tutsplus.com/tutorials/using-custom-post-types-to-create-a-killer-portfolio–wp-20565

Widget Area:
http://www.wpreads.com/2013/03/creating-custom-widget-area-in-wordpress-theme.html

HTML to WordPress theme tutorial:
http://www.wpexplorer.com/create-wordpress-theme-html-1/

Installing WordPress locally

Install WordPress locally with XAMPP:
http://premium.wpmudev.org/blog/how-to-install-wordpress-locally-for-pcwindows-with-xampp/

Install WordPress locally with MAMP:
http://codex.wordpress.org/Installing_WordPress_Locally_on_Your_Mac_With_MAMP

Resources

Roots bootstrap theme (we use this for every site):
http://roots.io/

Advanced custom fields:
http://www.advancedcustomfields.com/

ACF repeater field:
http://www.advancedcustomfields.com/add-ons/repeater-field/

ACF gallery field:
http://www.advancedcustomfields.com/add-ons/gallery-field/

ACF options page:
http://www.advancedcustomfields.com/add-ons/options-page/

ACF contact form 7 field:
https://github.com/taylormsj/acf-cf7-field

ACF JQuery date picker field:
https://wordpress.org/plugins/acf-field-date-time-picker/

Contact form 7:
https://wordpress.org/plugins/contact-form-7/