Skip to content

Instantly share code, notes, and snippets.

@xafarali
xafarali / parent_template.php
Created June 9, 2013 19:00
Wordpress template redirection for child pages. Adopt Parent template if its assigned.
// Custom Template Inheritance -----------------------------
function custom_template_override () {
if( is_page() ) {
global $post;
if( $post->post_parent ) {
$parent_page_template = get_post_meta($post->post_parent,'_wp_page_template',true);
$current_page_template = get_post_meta($post->ID, '_wp_page_template' , true );
@xafarali
xafarali / custom body class.php
Created June 9, 2013 20:08
Custom Body class
// Body Class
function add_body_class( $classes )
{
global $is_iphone;
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
@xafarali
xafarali / post_page_content.php
Created June 9, 2013 20:11
Post the page content in template via page id or slug
$pageID = 'page name or slug';
get_ID_by_slug($pageID );
// page id by slug
function get_ID_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
@xafarali
xafarali / register_que_deque.php
Created June 9, 2013 21:44
Register , Enqueue & Dequeue Scripts and Styles
// Enqueue Styles
function load_styles() {
wp_enqueue_style('AD-Gallery', $this->plugin_url . 'css/ad-gallery.css', false, '', 'screen');
wp_enqueue_style('jScrollPane', $this->plugin_url . 'css/jScrollPane.css', false, '', 'screen');
}
// Enqueue Scripts
function load_scripts() {
@xafarali
xafarali / get_thumbnail_url.php
Created June 9, 2013 22:01
Get Thumbnail URL
/* GET THUMBNAIL URL */
function get_image_url(){
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'large');
$image_url = $image_url[0];
echo $image_url;
}
@xafarali
xafarali / add_recent_post_shortcode.php
Created June 9, 2013 22:04
Add Recent Post shortcode
// Shortcode for recent post
add_shortcode('ss_recentpost','ss_recent_post');
// add_filter('the_content', 'do_shortcode', 11);
add_filter('widget_text', 'do_shortcode');
function ss_recent_post($attr) {
@xafarali
xafarali / add_thbnail_sizes.php
Created June 9, 2013 22:11
Add Thumbnail Sizes
/* FEATURED THUMBNAILS */
if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9
add_theme_support( 'post-thumbnails' );
}
add_image_size('small-thumbnail', 80, 80, true);
/* ===============================================
@xafarali
xafarali / post_post_thumb.php
Created June 9, 2013 22:19
Post Thumbnail in Loop
<?php if ( has_post_thumbnail()) : ?>
<span class="post-thumb">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php the_post_thumbnail('thumbnail'); ?></a>
</span>
<?php endif; ?>
@xafarali
xafarali / register Post type.php
Created June 9, 2013 22:28
Register Post Type
///////////////////////////////////
// Custom Post Type , Video
///////////////////////////////////
// Custom Post - Project
function create_banner() {
// label for post type project.
@xafarali
xafarali / custom_post_in_loop.php
Created June 9, 2013 22:42
Add Custom Post In Master Loop
<?php
if (is_archive() || is_category() || is_search() ) {
global $query_string;
parse_str( $query_string, $args );
$args['post_type'] = array( 'ss-video', 'post' );
query_posts( $args );
}
?>