Skip to content

Instantly share code, notes, and snippets.

@deepak125
Created July 23, 2015 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepak125/96109fb01660027f7132 to your computer and use it in GitHub Desktop.
Save deepak125/96109fb01660027f7132 to your computer and use it in GitHub Desktop.
<?php
/* Set Featured Image for pages */
add_theme_support('post-thumbnails', array('post', 'page'));
/* Featured Image URL */
function featured_img_url($mdw_featured_img_size, $id = NULL) {
if ($id != NULL) {
$mdw_image_id = get_post_thumbnail_id($id);
} else {
$mdw_image_id = get_post_thumbnail_id();
}
$mdw_image_url = wp_get_attachment_image_src($mdw_image_id, $mdw_featured_img_size);
$mdw_image_url = $mdw_image_url[0];
return $mdw_image_url;
}
/* Custom Menus */
register_nav_menus(array(
'primary' => __('Primary Navigation', 'gs-station'),
'secondary' => __('Secondary Navigation', 'footer-nav')
));
/* Upload Folder URL */
function upload_url($file) {
$url = bloginfo('url') . '/wp-content/uploads/' . $file;
return $url;
}
/* Widgets */
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Sidebar Posts'
));
register_sidebar(array(
'name' => 'Sidebar on Pages'
));
register_sidebar(array(
'name' => 'Footer Left',
));
register_sidebar(array(
'name' => 'Footer center',
));
register_sidebar(array(
'name' => 'Footer Right',
));
register_sidebar(array(
'name' => 'Footer',
));
register_sidebar(array(
'name' => 'Last minute side widget',
));
register_sidebar(array(
'name' => 'by land side widget',
));
register_sidebar(array(
'name' => 'Search bottom widget',
));
}
//REMOVING THE TEXT '[.....] FROM EXCERPT
function new_excerpt_more($more) {
return ' <a href="' . get_permalink() . '">[...]</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
//Get First Image
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches[1][0];
if (empty($first_img)) {
$first_img = "";
}
return $first_img;
}
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
set_post_thumbnail_size(290, 170);
}
function the_breadcrumb() {
// Settings
$id = 'breadcrumbs';
$class = 'breadcrumbs pull-right';
$home_title = 'Home';
// Get the query & post information
global $post, $wp_query;
$category = get_the_category();
// Build the breadcrums
echo '<ul id="' . $id . '" class="' . $class . '">';
// Do not display on the homepage
if (!is_front_page()) {
// Home page
echo '<li class="item-home"><a class="bread-link bread-home" href="' . get_home_url() . '" title="' . $home_title . '">' . $home_title . '</a></li>';
if (is_single()) {
// Single post (Only display the first category)
echo '<li class="item-cat item-cat-' . $category[0]->term_id . ' item-cat-' . $category[0]->category_nicename . '"><a class="bread-cat bread-cat-' . $category[0]->term_id . ' bread-cat-' . $category[0]->category_nicename . '" href="' . get_category_link($category[0]->term_id) . '" title="' . $category[0]->cat_name . '">' . $category[0]->cat_name . '</a></li>';
echo '<li class="separator separator-' . $category[0]->term_id . '"> ' . $separator . ' </li>';
echo '<li class="item-current item-' . $post->ID . '"><strong class="bread-current bread-' . $post->ID . '" title="' . get_the_title() . '">' . get_the_title() . '</strong></li>';
} else if (is_category()) {
// Category page
echo '<li class="item-current item-cat-' . $category[0]->term_id . ' item-cat-' . $category[0]->category_nicename . '"><strong class="bread-current bread-cat-' . $category[0]->term_id . ' bread-cat-' . $category[0]->category_nicename . '">' . $category[0]->cat_name . '</strong></li>';
} else if (is_page()) {
// Standard page
if ($post->post_parent) {
// If child page, get parents
$anc = get_post_ancestors($post->ID);
// Get parents in the right order
$anc = array_reverse($anc);
// Parent page loop
foreach ($anc as $ancestor) {
$parents .= '<li class="item-parent item-parent-' . $ancestor . '"><a class="bread-parent bread-parent-' . $ancestor . '" href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li>';
$parents .= '<li class="separator separator-' . $ancestor . '"> ' . $separator . ' </li>';
}
// Display parent pages
echo $parents;
// Current page
echo '<li class="item-current item-' . $post->ID . '"><strong title="' . get_the_title() . '"> ' . get_the_title() . '</strong></li>';
} else {
// Just display current page if not parents
echo '<li class="item-current item-' . $post->ID . '"><strong class="bread-current bread-' . $post->ID . '"> ' . get_the_title() . '</strong></li>';
}
} else if (is_tag()) {
// Tag page
// Get tag information
$term_id = get_query_var('tag_id');
$taxonomy = 'post_tag';
$args = 'include=' . $term_id;
$terms = get_terms($taxonomy, $args);
// Display the tag name
echo '<li class="item-current item-tag-' . $terms[0]->term_id . ' item-tag-' . $terms[0]->slug . '"><strong class="bread-current bread-tag-' . $terms[0]->term_id . ' bread-tag-' . $terms[0]->slug . '">' . $terms[0]->name . '</strong></li>';
} elseif (is_day()) {
// Day archive
// Year link
echo '<li class="item-year item-year-' . get_the_time('Y') . '"><a class="bread-year bread-year-' . get_the_time('Y') . '" href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</a></li>';
echo '<li class="separator separator-' . get_the_time('Y') . '"> ' . $separator . ' </li>';
// Month link
echo '<li class="item-month item-month-' . get_the_time('m') . '"><a class="bread-month bread-month-' . get_the_time('m') . '" href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time('M') . '">' . get_the_time('M') . ' Archives</a></li>';
echo '<li class="separator separator-' . get_the_time('m') . '"> ' . $separator . ' </li>';
// Day display
echo '<li class="item-current item-' . get_the_time('j') . '"><strong class="bread-current bread-' . get_the_time('j') . '"> ' . get_the_time('jS') . ' ' . get_the_time('M') . ' Archives</strong></li>';
} else if (is_month()) {
// Month Archive
// Year link
echo '<li class="item-year item-year-' . get_the_time('Y') . '"><a class="bread-year bread-year-' . get_the_time('Y') . '" href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</a></li>';
echo '<li class="separator separator-' . get_the_time('Y') . '"> ' . $separator . ' </li>';
// Month display
echo '<li class="item-month item-month-' . get_the_time('m') . '"><strong class="bread-month bread-month-' . get_the_time('m') . '" title="' . get_the_time('M') . '">' . get_the_time('M') . ' Archives</strong></li>';
} else if (is_year()) {
// Display year archive
echo '<li class="item-current item-current-' . get_the_time('Y') . '"><strong class="bread-current bread-current-' . get_the_time('Y') . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</strong></li>';
} else if (is_author()) {
// Auhor archive
// Get the author information
global $author;
$userdata = get_userdata($author);
// Display author name
echo '<li class="item-current item-current-' . $userdata->user_nicename . '"><strong class="bread-current bread-current-' . $userdata->user_nicename . '" title="' . $userdata->display_name . '">' . 'Author: ' . $userdata->display_name . '</strong></li>';
} else if (get_query_var('paged')) {
// Paginated archives
echo '<li class="item-current item-current-' . get_query_var('paged') . '"><strong class="bread-current bread-current-' . get_query_var('paged') . '" title="Page ' . get_query_var('paged') . '">' . __('Page') . ' ' . get_query_var('paged') . '</strong></li>';
} else if (is_search()) {
// Search results page
echo '<li class="item-current item-current-' . get_search_query() . '"><strong class="bread-current bread-current-' . get_search_query() . '" title="Search results for: ' . get_search_query() . '">Search results for: ' . get_search_query() . '</strong></li>';
} elseif (is_404()) {
// 404 page
echo '<li>' . 'Error 404' . '</li>';
}
}
echo '</ul>';
}
//ExcerptLeangth
function custom_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'custom_excerpt_length', 999);
//Image Resize Blog
// hook into the init action and call create_book_taxonomies when it fires
add_action('init', 'create_hotel_taxonomies', 0);
// create two taxonomies, genres and writers for the post type "book"
function create_hotel_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x('Destination Pages', 'taxonomy general name'),
'singular_name' => _x('Destination Page', 'taxonomy singular name'),
'search_items' => __('Search Destination Pages'),
'all_items' => __('All Destination Pages'),
'parent_item' => __('Parent Destination Page'),
'parent_item_colon' => __('Parent Destination Page:'),
'edit_item' => __('Edit Destination Page'),
'update_item' => __('Update Destination Page'),
'add_new_item' => __('Add New Destination Page'),
'new_item_name' => __('New Destination Page'),
'menu_name' => __('Destination Pages'),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'destination-pages'),
);
register_taxonomy('destination_pages', array('destinations'), $args);
//country taxonomy
$labels = array(
'name' => _x('Country', 'taxonomy general name'),
'singular_name' => _x('Country', 'taxonomy singular name'),
'search_items' => __('Search Countries'),
'all_items' => __('All Countries'),
'parent_item' => __('Parent Country'),
'parent_item_colon' => __('Parent Country:'),
'edit_item' => __('Edit Country'),
'update_item' => __('Update Country'),
'add_new_item' => __('Add New Country'),
'new_item_name' => __('New Country'),
'menu_name' => __('Country'),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'country'),
);
register_taxonomy('country', array('destinations'), $args);
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x('Category', 'taxonomy general name'),
'singular_name' => _x('Category', 'taxonomy singular name'),
'search_items' => __('Search Destination Category'),
'all_items' => __('All Destination Categories'),
'parent_item' => __('Parent Destination Category'),
'parent_item_colon' => __('Parent Destination Category:'),
'edit_item' => __('Edit Destination Category'),
'update_item' => __('Update Destination Category'),
'add_new_item' => __('Add New Destination Category'),
'new_item_name' => __('New Destination Category'),
'menu_name' => __('Categories'),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'destination-category'),
);
register_taxonomy('destination_category', array('destinations'), $args);
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x('Brands', 'taxonomy general name'),
'singular_name' => _x('Brand Page', 'taxonomy singular name'),
'search_items' => __('Search Brands'),
'all_items' => __('All Brands'),
'parent_item' => __('Parent Brand'),
'parent_item_colon' => __('Parent Brand:'),
'edit_item' => __('Edit Brand'),
'update_item' => __('Update Brand'),
'add_new_item' => __('Add New Brand'),
'new_item_name' => __('New Brand'),
'menu_name' => __('Destination Brands'),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'brands'),
);
register_taxonomy('brands', 'destinations', $args);
}
/**
*
* Register Post type
*
* * */
add_action('init', 'Destination_init');
/**
* Register a hotel post type.
*
*/
function destination_init() {
$labels = array(
'name' => _x('Destination', 'post type general name', 'C'),
'singular_name' => _x('Destination', 'post type singular name', 'your-plugin-textdomain'),
'menu_name' => _x('Destinations', 'admin menu', 'your-plugin-textdomain'),
'name_admin_bar' => _x('Destination', 'add new on admin bar', 'your-plugin-textdomain'),
'add_new' => _x('Add New', 'Destination', 'your-plugin-textdomain'),
'add_new_item' => __('Add Destination', 'your-plugin-textdomain'),
'new_item' => __('New Destination', 'your-plugin-textdomain'),
'edit_item' => __('Edit Destination', 'your-plugin-textdomain'),
'view_item' => __('View Destination', 'your-plugin-textdomain'),
'all_items' => __('All Destinations', 'your-plugin-textdomain'),
'search_items' => __('Search Destinations', 'your-plugin-textdomain'),
'parent_item_colon' => __('Parent Destination', 'your-plugin-textdomain'),
'not_found' => __('No Destination found.', 'your-plugin-textdomain'),
'not_found_in_trash' => __('No Destination found in Trash.', 'your-plugin-textdomain')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'destinations'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 5,
'taxonomies' => array('destination_category', 'destination_pages', 'brands', 'country'),
'supports' => array('title', 'editor', 'author', 'thumbnail', 'custom-fields')
);
register_post_type('destinations', $args);
}
add_image_size('blog-size', 360, 221, array('center', 'center'));
add_image_size('home-blog-size', 371, 222, true, array('center', 'center'));
//add_action('admin_init','increase_size_limit');
//function increase_size_limit(){
// ini_set('memory_limit', '-1'); //increase memory limit temporarily
//// echo memory_get_usage(true);
//}
function my_facetwp_sort_options($options, $params) {
$options['rating'] = array(
'label' => 'Rating',
'query_args' => array(
'orderby' => 'meta_value_num', // sort by numerical custom field
'meta_key' => 'rating', // required when sorting by custom fields
'order' => 'DESC', // descending order
)
);
return $options;
}
add_filter('facetwp_sort_options', 'my_facetwp_sort_options', 10, 2);
function my_facetwp_pager_html($output, $params) {
$output = '';
$page = $params['page'];
$total_pages = $params['total_pages'];
if ($page > 1) {
$output .= '<a class="facetwp-page" data-page="' . ($page - 1) . '">Previous</a>';
}
if ($page < $total_pages && $total_pages > 1) {
$pages_to_show = $total_pages > 7 ? 7 : $total_pages;
for ($i = 2; $i < $pages_to_show; $i++) {
$output .= '<a class="facetwp-page" data-page="' . ($i) . '">' . $i . '</a>';
}
if ($total_pages > 7) {
if (floor($total_pages / 4) > $pages_to_show)
$output .= '<a class="facetwp-page" data-page="' . floor($total_pages / 4) . '">' . floor($total_pages / 4) . '</a>';
if (floor($total_pages / 3) > floor($total_pages / 4))
$output .= '<a class="facetwp-page" data-page="' . floor($total_pages / 3) . '">' . floor($total_pages / 3) . '</a>';
if (floor($total_pages / 2) > floor($total_pages / 3))
$output .= '<a class="facetwp-page" data-page="' . floor($total_pages / 2) . '">' . floor($total_pages / 2) . '</a>';
if (($total_pages) > (floor($total_pages / 2)) + 2)
$output .= '<a class="facetwp-page" data-page="' . floor($total_pages - 2) . '">' . ($total_pages - 2) . '</a>';
}
if (($total_pages) > ($page))
$output .= '<a class="facetwp-page" data-page="' . ($page + 1) . '">Next</a>';
if (($total_pages) > floor($total_pages / 2) && $total_pages > $page + 1)
$output .= '<a class="facetwp-page" data-page="' . floor($total_pages) . '">Last</a>';
}
return $output;
}
add_filter('facetwp_pager_html', 'my_facetwp_pager_html', 10, 2);
function my_facetwp_result_count($output, $params) {
$output = $params['total'] . ' results found';
return $output;
}
add_filter('facetwp_result_count', 'my_facetwp_result_count', 10, 2);
function pre($vari) {
echo "<pre>";
print_r($vari);
echo "</pre>";
}
//listing shortcode
function listbox($atts, $content = null) {
extract(shortcode_atts(
array(
'link' => '',
'imgsrc' => '',
'title' => '',
'location' => '',
'price' => '',
), $atts));
$markup = '<article class = "list-box">
<figure class = "col-sm-5 col-md-4">
<a title = "$title" href = "' . $link . '" class = "hover-effect"><img width = "270" height = "160" alt = "" src = "' . $imgsrc . '"></a>
</figure>
<div class = "detail col-sm-7 col-md-8">
<header>
<div class = "header-title">
<h4 class = "box-title">' . $title . '<small><i class = "fa fa-map-marker yellow-color"></i> ' . $location . '</small></h4>
</div>
</header>
<p>' . do_shortcode($content) . '</p>
<div class = "price">' . $price . '</div>
<a href = "' . $link . '" class = "select-btn">Select</a>
</div>
</article>';
return $markup;
}
add_shortcode('listbox', 'listbox');
function content($num) {
$theContent = get_the_content();
$output = preg_replace('/<img[^>]+./', '', $theContent);
$output = preg_replace('/<blockquote>.*<\/blockquote>/', '', $output);
$output = preg_replace('|\[(.+?)\](.+?\[/\\1\])?|s', '', $output);
$limit = $num + 1;
$content = explode(' ', $output, $limit);
array_pop($content);
$content = implode(" ", $content) . "...";
echo $content;
}
function short_desc($theContent, $num) {
$output = preg_replace('/<img[^>]+./', '', $theContent);
$output = preg_replace('/<blockquote>.*<\/blockquote>/', '', $output);
$output = preg_replace('|\[(.+?)\](.+?\[/\\1\])?|s', '', $output);
$limit = $num + 1;
$content = explode(' ', $output, $limit);
array_pop($content);
$content = implode(" ", $content) . "...";
echo $content;
}
add_action('after_setup_theme', 'country_image');
function country_image() {
add_image_size('country', 450, 350, array( 'left', 'center' )); // (cropped)
}
function my_facetwp_is_main_query( $is_main_query, $query ) {
if ( isset( $query->query_vars['facetwp'] ) ) {
$is_main_query = true;
}
return $is_main_query;
}
add_filter( 'facetwp_is_main_query', 'my_facetwp_is_main_query', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment