This website uses cookies to remember you and improve your experience. For more info see our Privacy Policy.

  • About
  • Websites
    • Business Websites
    • Author Websites
  • SEO
  • Portfolio
    • Author Web Design
    • Business Web Design
    • Custom Graphics
    • Logos
  • Services & Pricing
    • Author Website Packages
    • Website Hosting
    • Page Speed Optimization
    • SEO
    • Local SEO
  • MyBookTable
    • MyBookTable Support
  • Contact
  • Hire Us

Mobile Menu

  • Menu
  • Skip to right header navigation
  • Skip to main content

Stormhill Media

Custom websites for every type of business

Header Right

  • About
  • Websites
    • Business Websites
    • Author Websites
  • SEO
  • Portfolio
    • Author Web Design
    • Business Web Design
    • Custom Graphics
    • Logos
  • Services & Pricing
    • Author Website Packages
    • Website Hosting
    • Page Speed Optimization
    • SEO
    • Local SEO
  • MyBookTable
    • MyBookTable Support
  • Contact
  • Hire Us

Blog

Home » Blog

Mobile Header.php

by Daniel Camomile · In: Code Snippets · on Feb 23, 2012

<?php /** * The Header for our theme. * * Displays all of the <head> section and everything up till <div id=”main”> * * @package WordPress * @subpackage Twenty_Eleven * @since Twenty Eleven 1.0 */ global $is_iphone; if ( $is_iphone || $_GET[‘iam’]==’testing’ ) { include( STYLESHEETPATH . ‘/mobile/header.php’ ); } else { include( STYLESHEETPATH . ‘/inc_header.php’ ); } ?> Basically, the proper way to use $is_iphone.  This example uses it to call two different header.php include files, but it could be used to call different css files or different template files, or whatever, basically.  inc_header.php is the default header.php for …

Mobile Header.phpRead More

Category: Code Snippets

Mullet

by Daniel Camomile · In: Code Snippets · on Feb 20, 2012

// /* This code goes in index.php */ <?php if ( have_posts() ) : ?> <?php /* Our Mullet Function begins here – Katie Suess 12/28/11 */ $classnum = count(get_body_class()); /* fetch body classes */ $classarr = get_body_class(); /* make it a testable variable */ for ($i = 0; $i <= $classnum; $i++) { $bodyclass = $classarr[$i]; if ($bodyclass == paged) { $excerpt_trigger = 1; /* No Mullet on Deeper Pages */ break 1; /* exit the while */ } else { $excerpt_trigger = 0; /* Set Count For Mullet */ } } ?> <?php /* Start the Loop */ …

MulletRead More

Category: Code Snippets

Manual Canonical Redirects

by Daniel Camomile · In: Code Snippets · on Feb 20, 2012

If you need to make sure non-www links end up on www… #Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^yoursite.com [NC] RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301]

Manual Canonical RedirectsRead More

Category: Code Snippets

Show Featured Image

by Daniel Camomile · In: Code Snippets · on Feb 20, 2012

after setting featured image. parameter size accepts thumbnail, medium, large or custom eg. array(230,234) <?php $theattr = array( ‘src’ => $src, ‘class’ => “attachment-$size”, ‘alt’ => trim(strip_tags( $attachment->post_excerpt )), ‘title’ => trim(strip_tags( $attachment->post_title )), ); the_post_thumbnail( ‘large’, $theattr ); ?>

Show Featured ImageRead More

Category: Code Snippets

get a single row from a table in the db

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

versatile way to get single piece of info related to something you already have $user = $wpdb->get_row($wpdb->prepare(“SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s”, $key, $login)); if ( !empty( $user ) ){ $username = $user->name; }

get a single row from a table in the dbRead More

Category: Code Snippets

Truncate Text

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

put in functions to truncate a post excerpt or something <?php function ttruncat($text,$numb) { if (strlen($text) > $numb) { $text = substr($text, 0, $numb); $text = substr($text,0,strrpos($text,” “)); $etc = ” …”; $text = $text.$etc; } return $text; } ?>

Truncate TextRead More

Category: Code Snippets

WP Nav Menu

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

place a nav menu anywhere <?php $navargs = array( ‘theme_location’ => , ‘menu’ => , ‘container’ => ‘div’, ‘container_class’ => , ‘container_id’ => , ‘menu_class’ => ‘menu’, ‘menu_id’ => , ‘echo’ => true, ‘fallback_cb’ => ‘wp_page_menu’, ‘before’ => , ‘after’ => , ‘link_before’ => , ‘link_after’ => , ‘depth’ => 0, ‘walker’ => ); ?> <div class=”access”> <?php wp_nav_menu($navargs); ?> </div>

WP Nav MenuRead More

Category: Code Snippets

Include a file

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

<?php include(TEMPLATEPATH . ‘/includes/featured.php’); ?> If using a child theme use STYLESHEETPATH instead <?php include(STYLESHEETPATH . ‘/includes/featured.php’); ?>

Include a fileRead More

Category: Code Snippets

Show all errors

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

if you get the white screen in WordPress, try this in wp-config.php but keep it commented out most of the time to hide misc. errors from normal viewers define(‘WP_DEBUG’, true);

Show all errorsRead More

Category: Code Snippets

MENU – show class in wp_list_pages for links that have kids

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

This comes in handy if you are using a list_page menu and need to change the style of menu elements that have children, liks add an arrow. This needs to be in the functions file. add_filter(‘page_css_class’, ‘nice_navigation_page_css_class’, 10, 2); /** * adds class “page-has-children” to all pages that have children * @param array $class. The page css class being modified, passed as an array from Walker_Page * @param object $page. The page object passed from Walker_Page * @return array Returns the new page css class. */ function nice_navigation_page_css_class($class, $page) { // check if current page has children $children = get_pages(‘child_of=’.$page->ID); …

MENU – show class in wp_list_pages for links that have kidsRead More

Category: Code Snippets

Show Logged in User Info

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

<?php global $current_user; get_currentuserinfo(); echo ‘Username: ‘ . $current_user->user_login . “n”; echo ‘User email: ‘ . $current_user->user_email . “n”; echo ‘User first name: ‘ . $current_user->user_firstname . “n”; echo ‘User last name: ‘ . $current_user->user_lastname . “n”; echo ‘User display name: ‘ . $current_user->display_name . “n”; echo ‘User ID: ‘ . $current_user->ID . “n”; ?>

Show Logged in User InfoRead More

Category: Code Snippets

Show all sql errors

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

add this right after the sql statement line $wpdb->show_errors();  

Show all sql errorsRead More

Category: Code Snippets

Use a shortcode in a template

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

<?php do_shortcode(‘[shortcode]’); ?>

Use a shortcode in a templateRead More

Category: Code Snippets

Update a single row in the db.

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

<?php $wpdb->query( ” UPDATE $wpdb->posts SET post_parent = 7 WHERE ID = 15 AND post_status = ‘static’ ” ); ?>

Update a single row in the db.Read More

Category: Code Snippets

Blog Info Tags

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

Usually needed for displaying the stylesheet directory for use in file paths, put lots of other good uses as well Format <?php bloginfo(‘stylesheet_directory’); ?> Complete List – follow the same format as above name                 = Testpilot description          = Just another WordPress blog admin_email          = admin@example url                  = https://example/home wpurl                = https://example/home/wp stylesheet_directory = https://example/home/wp/wp-content/themes/child-theme stylesheet_url       = https://example/home/wp/wp-content/themes/child-theme/style.css template_directory   = https://example/home/wp/wp-content/themes/parent-theme template_url         = https://example/home/wp/wp-content/themes/parent-theme atom_url             = https://example/home/feed/atom rss2_url             = https://example/home/feed rss_url              = https://example/home/feed/rss pingback_url         = https://example/home/wp/xmlrpc.php rdf_url              = https://example/home/feed/rdf comments_atom_url    = https://example/home/comments/feed/atom comments_rss2_url    = https://example/home/comments/feed charset              = UTF-8 html_type            = text/html language             = en-US text_direction       = ltr version              = 3.1

Blog Info TagsRead More

Category: Code Snippets

Show All Query Vars

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

This is great for troubleshooting. If you need to see the main variables WP is loading, try sticking this in your template and refreshing. For more info, try this without the ->query_vars at the end. <pre><?php print_r($wp_query->query_vars); ?></pre>

Show All Query VarsRead More

Category: Code Snippets

List Subpages

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

This is great for custom sub nav of pages <?php // list the About subpage menu $args=array( ‘showposts’=>5, // how many to show ‘sort_column’=>’menu_order’, ‘post_type’=>’page’, // page or post ‘child_of’ => $post->ID, ); $myPosts = get_pages($args); if ($myPosts) { foreach ($myPosts as $myPage) { $permalink = get_permalink($myPage->ID); } } ?>

List SubpagesRead More

Category: Code Snippets

Display Content of a post or page anywhere

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

This is useful if you have a place on the sidebar or a box on the homepage where you want to have some changeable content. Add the content to a post or page and then output it wherever you want it using this. <?php // know the id of the page you want to display $theId = 668; // get the post $feature = get_post($theId); // get the content for the post. You can also get anything else for the post, post_title, post_excerpt… $content = $feature->post_content; echo $content; ?>

Display Content of a post or page anywhereRead More

Category: Code Snippets

Outputting array elements from query_vars

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

If you use <pre><?php print_r($wp_query->query_vars); ?></pre> to display the query var array and decide to use one of the elements, here are some simple examples the get_query_var() function that outputs them. <?php $curcat = get_query_var(‘category_name’); $curtax = get_query_var(‘taxonomy’); $curterm = get_query_var(‘term’); ?>  

Outputting array elements from query_varsRead More

Category: Code Snippets

Custom Database Query – WP Style

by Daniel Camomile · In: Code Snippets · on Feb 19, 2012

Get just about anything and display it. <?php $sql = “SELECT event_begin, event_end, event_title, event_short FROM wp_my_calendar ORDER BY event_begin LIMIT 3”; $holidays = $wpdb->get_results($sql); if ($holidays) { foreach ($holidays as $holiday) { $eventstart = $holiday->event_start; } ?>

Custom Database Query – WP StyleRead More

Category: Code Snippets

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 7
  • Page 8
  • Page 9
  • Page 10
  • Go to Next Page »

Site Footer

Quick Links:

  • Contact Us
  • Pricing & Services
  • Sitemap
  • Terms/Conditions
  • Privacy Policy
  • Business Websites
  • Author Websites
  • SEO Services
(903) 213-5266‬

Copyright © 2026 · Stormhill Media All Rights Reserved.
Website by Stormhill Media
Log in