RtThemesSupport

RtTh16 V 241 Themefunctions php

Sep 25th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.16 KB | None | 0 0
  1. <?php
  2. #-----------------------------------------
  3. #   RT-Theme theme_functions.php
  4. #   version: 1.0
  5. #-----------------------------------------
  6.  
  7.    
  8. #
  9. #   sub page layouts function
  10. #
  11.  
  12. function sub_page_layout($location,$sidebar){
  13.    
  14.     $sidebar = (!$sidebar) ? sidebar_location() : $sidebar;
  15.     $page_layout = ($sidebar=="full") ? "fullwidth" : "sidebarwidth";
  16.        
  17.     $content_location = ($sidebar =="left") ? $content_location="right" : $content_location="left";
  18.    
  19.     if($location=="subheader"){
  20.         echo '<div id="main" role="main" class="clearfix">';
  21.         echo    '<div class="sub_page '.$page_layout.' ">';
  22.         echo ($page_layout=="sidebarwidth") ? '<div class="content '.$content_location.' clearfix">' : '<div class="content '.$page_layout.' clearfix">';
  23.     }
  24.  
  25.     if($location=="subfooter"){
  26.         echo '</div>';
  27.  
  28.         if($page_layout=="sidebarwidth"){
  29.             echo '<div class="sidebar '.$sidebar.' clearfix">';
  30.                 get_template_part( 'sidebar', 'sidebar-core-file');
  31.             echo '</div>';
  32.         }
  33.        
  34.         echo '</div></div>';
  35.     }
  36.  
  37. }
  38.  
  39. #
  40. #   optional sidebar locations
  41. #
  42.  
  43. function sidebar_location(){
  44.     if(is_page() || is_single()) global $post;
  45.  
  46.     $sidebar    = get_option(THEMESLUG.'_sidebar_position'); //no specific sidebar location - use default
  47.     $metabox_selection  = (isset($post)) ? get_post_meta($post->ID, THEMESLUG.'custom_sidebar_position', true) : false ; //sidebar selection via metaboxes
  48.    
  49.    
  50.     // site part = regular pages
  51.     if(is_theme_page() || is_contact_page() ) $sidebar = (get_post_meta($post->ID, THEMESLUG.'custom_sidebar_position', true)) ? get_post_meta($post->ID, THEMESLUG.'custom_sidebar_position', true) : $sidebar ; //sidebar location regular page  
  52.    
  53.     // site part = blog
  54.     if(is_blog_page()) $sidebar  = ($metabox_selection ? $metabox_selection : ( get_option(THEMESLUG.'_sidebar_position_blog') ? get_option(THEMESLUG.'_sidebar_position_blog') : $sidebar ) );  
  55.  
  56.     // site part = product
  57.     if(is_product_page()) $sidebar  = ($metabox_selection   ? $metabox_selection : (    get_option(THEMESLUG.'_sidebar_position_product') ? get_option(THEMESLUG.'_sidebar_position_product') : $sidebar ) );    
  58.  
  59.     // site part = portfolio
  60.     if(is_portfolio_page()) $sidebar  = ($metabox_selection  ? $metabox_selection : (   get_option(THEMESLUG.'_sidebar_position_portfolio') ? get_option(THEMESLUG.'_sidebar_position_portfolio') : $sidebar ) );
  61.  
  62.     return $sidebar;
  63. }
  64.  
  65.  
  66.  
  67. #
  68. #   Get Page Layout
  69. #
  70.  
  71. function get_page_layout(){
  72.     if(is_page() || is_single()) global $post;
  73.    
  74.     $metabox_selection =  ($post) ? ( get_post_meta($post->ID, THEMESLUG.'custom_sidebar_position', true) )  ?  ( get_post_meta($post->ID, THEMESLUG.'custom_sidebar_position', true) )  : false : false; //fullwidth selection via metaboxes
  75.  
  76.     // site part = regular pages
  77.     if(is_theme_page() || is_contact_page()) $fullwidth = $metabox_selection;
  78.    
  79.     // site part = blog
  80.     if(is_blog_page()) $fullwidth = ($metabox_selection) ?  ($metabox_selection=="full" ? "fullwidth" : false ) : get_option(THEMESLUG.'_sidebar_position_blog')=="full" ? "fullwidth" : false;    
  81.        
  82.     return $fullwidth;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89. #
  90. # Add Class WP Menu - adds class for the first menu item
  91. #
  92.  
  93. function add_class_first_item($menu){
  94.    
  95.     $find="\"><a ";
  96.     $replace=" first\"><a ";
  97.     return preg_replace('/'.$find.'/', $replace, $menu, 1);
  98. }
  99.  
  100.  
  101. #
  102. # Remove more link in excerpts
  103. #
  104.  
  105. function no_excerpt_more($more) {
  106.     return '.. ';
  107. }
  108.  
  109. #
  110. # Get page count
  111. #
  112.  
  113. function get_page_count(){
  114.     global $wp_query;  
  115.     $count=array('page_count'=>$wp_query->max_num_pages,'post_count'=>$wp_query->post_count);
  116.     return $count;
  117. }
  118.  
  119.  
  120. #
  121. # Pagination
  122. #
  123. function get_pagination($range = 7){
  124.     global $paged, $wp_query;
  125.    
  126.     $max_page = $wp_query->max_num_pages;
  127.      
  128.     if($max_page > 1){
  129.     if(!$paged){
  130.       $paged = 1;
  131.     }
  132.  
  133.     if ($paged > 1){
  134.         echo "<li class=\"arrowleft\">";
  135.             previous_posts_link('←');
  136.         echo "</li>\n";
  137.     }
  138.     if($max_page > $range){
  139.     if($paged < $range){
  140.       for($i = 1; $i <= ($range + 1); $i++){
  141.         echo "<li";
  142.         if($i==$paged) echo " class='active'";
  143.         echo "><a href='" . get_pagenum_link($i) ."'>$i</a>";
  144.         echo "</li>\n";
  145.       }
  146.     }
  147.     elseif($paged >= ($max_page - ceil(($range/2)))){
  148.       for($i = $max_page - $range; $i <= $max_page; $i++){
  149.         echo "<li";
  150.         if($i==$paged) echo " class='active'";
  151.         echo "><a href='" . get_pagenum_link($i) ."'>$i</a>";
  152.         echo "</li>\n";
  153.       }
  154.     }
  155.     elseif($paged >= $range && $paged < ($max_page - ceil(($range/2)))){
  156.       for($i = ($paged - ceil($range/2)); $i <= ($paged + ceil(($range/2))); $i++){
  157.         echo "<li";
  158.         if($i==$paged) echo " class='active'";
  159.         echo "><a href='" . get_pagenum_link($i) ."'>$i</a>";
  160.         echo "</li>\n";
  161.       }
  162.     }
  163.     }
  164.     else{
  165.     for($i = 1; $i <= $max_page; $i++){
  166.         echo "<li";
  167.         if($i==$paged) echo " class=\"active\" ";
  168.         echo "><a href='" . get_pagenum_link($i) ."'>$i</a>";
  169.         echo "</li>\n";
  170.     }
  171.     }
  172.     if ($paged != $max_page){
  173.         echo "<li class=\"arrowright\">";
  174.         next_posts_link('→');
  175.         echo "</li>\n";
  176.     }
  177.    
  178.     }
  179. }
  180.  
  181.  
  182. #
  183. # checks page reserved for blog product or portfolio
  184. #
  185.  
  186. function is_theme_page(){
  187.     global $post;
  188.     if (!isset($post)) return false;
  189.     $post->ID = wpml_page_id($post->ID);
  190.    
  191.     if($post->ID != BLOGPAGE && $post->ID !=PRODUCTPAGE && $post->ID !=PORTFOLIOPAGE && $post->ID !=CONTACTPAGE  && is_page()){
  192.        return true;
  193.     }
  194.    
  195. }
  196.  
  197. #
  198. # checks theme parts that reserved for blog
  199. #
  200.  
  201. function is_blog_page(){
  202.     global $post;
  203.     if (!isset($post)) return false;
  204.     $post->ID = wpml_page_id($post->ID);
  205.    
  206.     if($post->ID == BLOGPAGE || is_category() || is_single() && $post->post_type!='products' && $post->post_type!='portfolio'  ){
  207.         return true;
  208.     }
  209.  
  210.     //check default blog template usage
  211.     if(get_post_meta($post->ID, THEMESLUG.'custom_sidebar_position', true) == "templateid_004" ){
  212.         return true;
  213.     }          
  214. }
  215.  
  216. #
  217. # checks theme parts that reserved for products
  218. #
  219.  
  220. function is_product_page(){
  221.     global $post,$taxonomy;
  222.     if (!isset($post)) return false;    
  223.     $post->ID = wpml_page_id($post->ID);
  224.    
  225.     if($post->ID == PRODUCTPAGE || $taxonomy=="product_categories" || $post->post_type=='products'){
  226.         return true;
  227.     }
  228.  
  229.     //check default product template usage
  230.     if(get_post_meta($post->ID, THEMESLUG.'custom_sidebar_position', true) == "templateid_003" ){
  231.         return true;
  232.     }
  233. }
  234.  
  235. #
  236. # checks theme parts that reserved for portfolio
  237. #
  238.  
  239. function is_portfolio_page(){
  240.     global $post,$taxonomy,$sidebar;
  241.     if (!isset($post)) return false;  
  242.     $post->ID = wpml_page_id($post->ID);
  243.    
  244.     if($post->ID == PORTFOLIOPAGE || $taxonomy=="portfolio_categories" || $post->post_type=='portfolio'){
  245.         return true;
  246.     }
  247.  
  248.     //check default porfolio template usage
  249.     if(get_post_meta($post->ID, THEMESLUG.'custom_sidebar_position', true) == "templateid_002" ){
  250.         return true;
  251.     }  
  252. }
  253.  
  254. #
  255. # checks theme parts that reserved for contact page
  256. #
  257.  
  258. function is_contact_page(){
  259.     global $post;
  260.     if (!isset($post)) return false;
  261.     $post->ID = wpml_page_id($post->ID);
  262.    
  263.     if($post->ID == CONTACTPAGE){
  264.         return true;
  265.     }
  266.  
  267.     //check default contact template usage
  268.     if(get_post_meta($post->ID, THEMESLUG.'custom_sidebar_position', true) == "templateid_005" ){
  269.         return true;
  270.     }      
  271. }
  272.  
  273. #
  274. # gets orginal paths of images when multi site mode active
  275. #
  276. if( ! function_exists("find_image_org_path") ){
  277.     function find_image_org_path($image) {
  278.         if(is_multisite()){
  279.             global $blog_id;
  280.             if (isset($blog_id) && $blog_id > 0) {
  281.                 if(strpos($image,get_bloginfo('wpurl'))!==false){//image is local
  282.                     if(empty(get_current_site(1)->path)){
  283.                         $the_image_path = get_current_site(1)->path.str_replace(get_blog_option($blog_id,'fileupload_url'),get_blog_option($blog_id,'upload_path'),$image);
  284.                     }else{
  285.                         $the_image_path = $image;
  286.                     }              
  287.                 }else{
  288.                     $the_image_path = $image;
  289.                 }
  290.             }else{
  291.                 $the_image_path = $image;
  292.             }
  293.         }else{
  294.             $the_image_path = $image;
  295.         }
  296.  
  297.         return rt_clean_thumbnail_ext($the_image_path);
  298.     }
  299. }
  300.  
  301.  
  302. #
  303. # set selected theme style to body tag
  304. #
  305.  
  306. function rt_body_class_name($classes) {
  307.     if (isset($_GET['theme_style'])) {
  308.         if ($_GET["theme_style"]=="dark") $classes[]='dark';
  309.         else $classes[] = get_option( THEMESLUG."_style" );
  310.     }
  311.     else $classes[] = get_option( THEMESLUG."_style" );
  312.     //$classes[] = get_option( THEMESLUG."_style" );
  313.     $classes[] = get_option( THEMESLUG."_boxed_design" ) ? 'boxed' : '' ;  
  314.     // return the $classes array
  315.     return $classes;
  316. }
  317.  
  318. #
  319. # returns a post ID from a url
  320. #
  321.  
  322. function rt_get_attachment_id_from_src ($image_src) {
  323.     global $wpdb;
  324.     $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
  325.     $id    = $wpdb->get_var($query);
  326.     return $id;
  327. }
  328.  
  329. #
  330. # find orginal image url - clean thumbnail extensions
  331. #
  332.  
  333. function rt_clean_thumbnail_ext ($image_src) {
  334.     $search = '#-\d+x\d+#';  
  335.     return preg_replace($search, "", $image_src);
  336. }
  337.  
  338. #
  339. # Exclude some custom post types from search
  340. #
  341. function excludePostsfromSearch($query) {
  342.     if ($query->is_search) {
  343.         $query->set('post_type', array("post","page","portfolio","products"));
  344.         $query->set('posts_per_page', 10);
  345.     }
  346.     return $query;
  347. }
  348. if(!is_admin()) add_filter('pre_get_posts','excludePostsfromSearch');
  349.  
  350. ?>
Advertisement
Add Comment
Please, Sign In to add comment