Code
Get Link to Featured Image for use in View
In functions.php create function and shortcode /** *************************************************** * get image src for featured image of post (large version) */ /* Register our short code at the appropriate time during the WordPress Boot process. */ add_action( ‘init’, ‘wpk_register_shortcodes’); function wpk_register_shortcodes(){ add_shortcode(‘my_get_thumbsrc’, ‘my_get_thumbsrc’); } /* Function to return the source url for the featured image of…
Read MoreShow Recent Posts in Template
In template: Default $args Usage: Recent Posts
Read MoreLoad Custom JS Scripts
To load a custom js script when, for instance page ID 434 is loaded place the following in theme functions.php: // load our own validation script on page 434 add_action( ‘wp_enqueue_scripts’, ‘babelscribe_load_scripts’ ); function babelscribe_load_scripts() { // register your script location, dependencies and version wp_register_script(‘action_script’, get_stylesheet_directory_uri().’/js/actions.js’, array(‘jquery’)); // enqueue the script if (is_page(434)) { //…
Read MoreQuerying the WordPress Database
This is a summary of basic ways to query the WordPress database: Basic Query returning an object:
Read MoreCustom Widget Area
Register a Custom Sidebar as described here Add widget to the sidebar. Use the following in your template file to show the sidebar (custom widget area) // Custom widget Area Start if( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘Left Column Widgets’) ) : endif; // Custom widget Area end where ‘Left Column Widgets’ is the registered name of the…
Read MoreInclude Path from Theme Folder
If you can’t use an absolute url to an include file due to server configuration you can use the ABSPATH WordPress constant: require_once(ABSPATH .’/Connections/boatparts.php’); If ABSPATH is not defined you can use this: require (dirname(__FILE__).”/makesessionid.php”);
Read MoreWP E-Commerce Sales Log Date Wrong Time Zone
Set the server timezone by adding this to top of your functions.php file of your theme: Time zones are detailed here: http://www.php.net/manual/en/timezones.php
Read MoreGet Post Type
Get post type for custom post types etc: get_post_type( $post->ID )
Read MoreGet ID of Parent Page
Test for a parent page and get its ID if($post->post_parent){ $parentID = ($post->post_parent); }
Read MoreCustom Field to Define Sidebar
Sidebar can be selected according to a custom field on the page:
Read More