Advertisement
contempoinc

theme-functions.php

Aug 21st, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 42.91 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Core Theme Functions
  4.  *
  5.  * @package WP Executive
  6.  * @subpackage Admin
  7.  */
  8.  
  9. if (is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" ) {
  10.     //Call action that sets
  11.     add_action('admin_head','ct_option_setup');
  12.     //Do redirect
  13.     header( 'Location: '.admin_url().'admin.php?page=ct-options' ) ;
  14. }
  15.  
  16. function ct_admin_head() {
  17.     ?>
  18.     <script>
  19.         jQuery(function(){
  20.             var message = '<p>This theme comes with a <a href="<?php echo admin_url('admin.php?page=functions.php'); ?>">comprehensive options panel</a>. This theme also supports widgets, please visit the <a href="<?php echo admin_url('widgets.php'); ?>">widgets settings page</a> to configure them.</p>';
  21.             jQuery('.themes-php #message2').html(message);
  22.         });
  23.     </script>
  24.     <?php
  25. }
  26.  
  27. // Body ID's
  28. function ct_body_id() {
  29.  
  30.     if (is_home()) {
  31.         echo ' id="home"';
  32.     } elseif (is_singular('listings')) {
  33.         echo ' id="listing"';
  34.     } elseif (is_single()) {
  35.         echo ' id="single"';
  36.     } elseif (is_page()) {
  37.         echo ' id="page"';
  38.     } elseif (is_search()) {
  39.         echo ' id="search"';
  40.     } elseif (is_archive()) {
  41.         echo ' id="archive"';
  42.     }
  43. }
  44.  
  45. // SEO Friendly Title Tags
  46. function ct_title() {
  47.    
  48.     if (is_category()) {
  49.         echo wp_title(''); echo ' - ';
  50.    
  51.     } elseif (function_exists('is_tag') && is_tag()) {
  52.         single_tag_title('Tag Archive for &quot;'); echo '&quot; - ';
  53.    
  54.     } elseif (is_archive()) {
  55.         wp_title(''); echo ' Archive - ';
  56.    
  57.     } elseif (is_page()) {
  58.         echo wp_title(''); echo ' - ';
  59.    
  60.     } elseif (is_search()) {
  61.         echo 'Search for &quot;'.esc_html($s).'&quot; - ';
  62.    
  63.     } elseif (!(is_404()) && (is_single()) || (is_page())) {
  64.         wp_title(''); echo ' - ';
  65.    
  66.     } elseif (is_404()) {
  67.         echo 'Not Found - ';
  68.    
  69.     } bloginfo('name');
  70.    
  71. }
  72.  
  73. // Add Editor Stylesheet Support
  74. if ( function_exists('add_editor_style') ) {
  75.     add_editor_style();
  76. }
  77.  
  78. // Add WordPress 3.0 Menu Support
  79. if ( function_exists('register_nav_menu') ) {
  80.     register_nav_menus( array( 'primary' => __( 'Primary Menu', 'contempo' ) ) );
  81.     register_nav_menus( array( 'footer' => __( 'Footer Menu', 'contempo' ) ) );
  82. }
  83.  
  84. function ct_nav() { ?>
  85.     <nav class="left clear">
  86.         <?php wp_nav_menu( array( 'container_id' => 'nav', 'theme_location' => 'primary') ); ?>
  87.     </nav>
  88. <?php }
  89.  
  90. function ct_footer_nav() { ?>
  91.     <nav class="left">
  92.         <?php wp_nav_menu( array( 'container_id' => 'footer-nav', 'theme_location' => 'footer') ); ?>
  93.     </nav>
  94. <?php }
  95.  
  96. function ct_wp_head() {
  97.    
  98.     if(get_option("ct_custom_favicon_url", true) !="") { ?>
  99.     <link rel="shortcut icon" href="<?php echo get_option("ct_custom_favicon_url", true); ?>" />
  100.     <?php } ?>
  101.    
  102.     <!--[if lt IE 9]>
  103.     <script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
  104.     <![endif]-->
  105.    
  106.     <?php if(is_single()) { ?>
  107.     <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/post-print.css" media="print" />
  108.     <?php } ?>
  109.    
  110.     <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/ct_dropdowns.css" media="screen" />
  111.    
  112.     <?php if(get_option("ct_alert", true) == "yes") { ?>
  113.     <!-- Alert Bar -->
  114.     <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.easing.1.3.js"></script>
  115.     <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.cookie.js"></script>
  116.     <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.ct.alertBar.js"></script>
  117.    
  118.         <?php if(get_option("ct_alert_sticky", true) == "yes" || get_option("ct_alert_fontcolor", true) || get_option("ct_alert_fontsize") || get_option("ct_alert_linkcolor", true) || get_option("ct_alert_bgcolor", true)) { ?>
  119.         <style type="text/css">
  120.         <?php if(get_option("ct_alert_sticky", true) == "yes") { ?>#alert-wrapper { position: fixed; top: 0;} section#main { margin-top: 50px;}<?php } ?>
  121.         <?php if(get_option("ct_alert_fontcolor", true) || get_option("ct_alert_fontsize") !="") { ?>#alert p { color: #<?php echo get_option("ct_alert_fontcolor", true); ?>; font-size: <?php echo get_option("ct_alert_fontsize", true); ?>;}<?php } ?>
  122.         <?php if(get_option("ct_alert_linkcolor", true) !="") { ?>#alert p a:link { color: #<?php echo get_option("ct_alert_linkcolor", true); ?>;}<?php } ?>
  123.         <?php if(get_option("ct_alert_bgcolor", true) !="") { ?>#alert, #alert-open { background-color: #<?php echo get_option("ct_alert_bgcolor", true); ?>;}<?php } ?>
  124.         </style>
  125.         <?php } ?>
  126.     <?php } ?>
  127.    
  128.     <?php if(is_post_type_archive('portfolio') || is_post_type_archive('products')) { ?>
  129.     <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.easing.1.3.js"></script>
  130.     <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.quicksand.js"></script>
  131.     <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.quicksand.init.js"></script>
  132.     <?php } ?>
  133.    
  134.     <?php if(is_single() || is_page()) { ?>
  135.     <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/comments.css" media="screen" />
  136.     <?php wp_enqueue_script( "comment-reply" ); ?>
  137.     <?php } ?>
  138.    
  139.     <?php if(get_option("ct_featured", true) == "yes") {
  140.         if(is_home() || get_post_type() == 'portfolio' || get_post_type() == 'products') { ?>
  141.             <!-- Nivo Slider -->
  142.             <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/nivo-slider.css" media="screen" />
  143.             <?php if(is_home()) { ?>
  144.             <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/home-nivo-slider.css" media="screen" />
  145.             <?php } ?>
  146.             <?php if( get_post_type() == 'portfolio' || get_post_type() == 'products' )  { ?>
  147.             <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/portfolio-nivo-slider.css" media="screen" />
  148.             <?php } ?>
  149.             <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.nivo.slider.pack.js"></script>
  150.             <script>
  151.             jQuery(window).load(function() {
  152.                jQuery('#slider').nivoSlider({
  153.                     effect:'<?php echo get_option("ct_nivo_effect", true); ?>',
  154.                     slices:<?php echo get_option("ct_nivo_slices", true); ?>,
  155.                     animSpeed:<?php echo get_option("ct_nivo_speed", true); ?>,
  156.                     pauseTime:<?php echo get_option("ct_nivo_pause", true); ?>,
  157.                     directionNav:<?php echo get_option("ct_nivo_arrows", true); ?>, //Next & Prev
  158.                     <?php if(is_home()) { ?>
  159.                     directionNavHide: false, //Only show on hover
  160.                     <?php } else { ?>
  161.                     directionNavHide: true,
  162.                     <?php } ?>
  163.                     controlNav:<?php echo get_option("ct_nivo_control", true); ?>, //1,2,3...
  164.                     pauseOnHover:<?php echo get_option("ct_nivo_pausehover", true); ?>, //Stop animation while hovering
  165.                     beforeChange: function(){},
  166.                     afterChange: function(){}
  167.                 });
  168.             });
  169.             </script>
  170.         <?php } ?>
  171.     <?php } ?>
  172.    
  173.     <!-- PrettyPhoto -->
  174.     <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/prettyPhoto.css" media="screen" />
  175.     <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.prettyPhoto.js"></script>
  176.    
  177.     <!-- Contact Form Validation and Ajax Submit -->
  178.     <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/validationEngine.jquery.css" media="screen" />
  179.     <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.validationEngine.js"></script>
  180.     <script>
  181.     // Ajax Submit
  182.     // Full documentation on this can be found at http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
  183.     jQuery(document).ready(function() {
  184.         jQuery("#contactform").validationEngine({
  185.             ajaxSubmit: true,
  186.                 ajaxSubmitFile: "<?php echo get_template_directory_uri(); ?>/includes/ajaxSubmit.php",
  187.                 ajaxSubmitMessage: "<?php echo stripslashes(get_option("ct_success", true)); ?>",
  188.             success :  false,
  189.             failure : function() {}
  190.         })
  191.     });
  192.     </script>
  193.    
  194.     <!-- Core Javascript -->
  195.     <script src="<?php echo get_template_directory_uri(); ?>/js/core.js"></script>
  196.    
  197.     <?php if(get_option("ct_stylesheet", true) =="fabric") { ?>
  198.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/fabric_1.gif) repeat;}</style>
  199.     <?php } elseif(get_option("ct_stylesheet", true) =="fabric2") { ?>
  200.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/fabric_2.gif) repeat;}</style>
  201.     <?php } elseif(get_option("ct_stylesheet", true) =="60lines") { ?>
  202.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/60degree_gray.gif) repeat;}</style>
  203.     <?php } elseif(get_option("ct_stylesheet", true) =="blackdenim") { ?>
  204.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/black_denim.gif) repeat;}</style>
  205.     <?php } elseif(get_option("ct_stylesheet", true) =="cork") { ?>
  206.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/cork_1.gif) repeat;}</style>
  207.     <?php } elseif(get_option("ct_stylesheet", true) =="graysand") { ?>
  208.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/gray_sand.gif) repeat;}</style>
  209.     <?php } elseif(get_option("ct_stylesheet", true) =="leather") { ?>
  210.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/leather_1.gif) repeat;}</style>
  211.     <?php } elseif(get_option("ct_stylesheet", true) =="metaldots") { ?>
  212.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/metal_dots.gif) repeat;}</style>
  213.     <?php } elseif(get_option("ct_stylesheet", true) =="metaldots") { ?>
  214.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/metal_dots.gif) repeat;}</style>
  215.     <?php } elseif(get_option("ct_stylesheet", true) =="paper") { ?>
  216.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/paper_1.gif) repeat;}</style>
  217.     <?php } elseif(get_option("ct_stylesheet", true) =="paper2") { ?>
  218.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/paper_2.gif) repeat;}</style>
  219.     <?php } elseif(get_option("ct_stylesheet", true) =="paper3") { ?>
  220.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/paper_3.gif) repeat;}</style>
  221.     <?php } elseif(get_option("ct_stylesheet", true) =="paper4") { ?>
  222.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/paper_4.gif) repeat;}</style>
  223.     <?php } elseif(get_option("ct_stylesheet", true) =="smoothwall") { ?>
  224.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/smooth_wall.gif) repeat;}</style>
  225.     <?php } elseif(get_option("ct_stylesheet", true) =="tactilenoise") { ?>
  226.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/tactile_noise.gif) repeat;}</style>
  227.     <?php } elseif(get_option("ct_stylesheet", true) =="whitecarbon") { ?>
  228.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/white_carbon.gif) repeat;}</style>
  229.     <?php } elseif(get_option("ct_stylesheet", true) =="whitesand") { ?>
  230.         <style>body { background: url(<?php echo get_template_directory_uri(); ?>/images/skins/white_sand.gif) repeat;}</style>
  231.     <?php } else { }   
  232.    
  233.     //Inject Custom Stylesheet
  234.     if(get_option("ct_usestyles", true) =="yes") { ?>
  235.         <?php include(TEMPLATEPATH . '/includes/custom_stylesheet.php'); ?>
  236.     <?php }
  237.    
  238.     //Inject Custom Fonts
  239.     if(get_option("ct_font", true) =="quattrocentosans") { ?>
  240.         <link type="text/css" href="http://fonts.googleapis.com/css?family=Quattrocento+Sans:regular" rel="stylesheet" />  
  241.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Quattrocento Sans', serif;}</style>
  242.     <?php } elseif(get_option("ct_font", true) =="varela") { ?>
  243.         <link type="text/css" href="http://fonts.googleapis.com/css?family=Varela+Round" rel="stylesheet" />  
  244.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Varela Round', sans-serif;}</style>  
  245.     <?php } elseif(get_option("ct_font", true) =="specialelite") { ?>
  246.         <link type="text/css" href="http://fonts.googleapis.com/css?family=Special+Elite:regular" rel="stylesheet" />
  247.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Special Elite', serif;}</style>
  248.     <?php } elseif(get_option("ct_font", true) =="sixcaps") { ?>
  249.         <link type="text/css" href="http://fonts.googleapis.com/css?family=Six+Caps:regular" rel="stylesheet" />
  250.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Six Caps', serif;}</style>
  251.     <?php } elseif(get_option("ct_font", true) =="ebgaramond") { ?>
  252.         <link type="text/css" href="http://fonts.googleapis.com/css?family=EB+Garamond:regular" rel="stylesheet" />
  253.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'EB Garamond', serif;}</style>
  254.     <?php } elseif(get_option("ct_font", true) =="terminaldosislight") { ?>
  255.         <link  href="http://fonts.googleapis.com/css?family=Terminal+Dosis+Light:regular" rel="stylesheet" />
  256.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Terminal Dosis Light', serif;}</style>
  257.     <?php } elseif(get_option("ct_font", true) =="michroma") { ?>
  258.         <link  href="http://fonts.googleapis.com/css?family=Michroma:regular" rel="stylesheet" />
  259.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Michroma', serif;}</style>
  260.     <?php } elseif(get_option("ct_font", true) =="bevan") { ?>
  261.         <link  href="http://fonts.googleapis.com/css?family=Bevan:regular" rel="stylesheet" >
  262.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Bevan', serif;}</style>
  263.     <?php } elseif(get_option("ct_font", true) =="droidsans") { ?>
  264.         <link type="text/css" href="http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold" rel="stylesheet" />
  265.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Droid Sans', serif;}</style>
  266.     <?php } elseif(get_option("ct_font", true) =="droidserif") { ?>
  267.         <link  href="http://fonts.googleapis.com/css?family=Droid+Serif:regular,italic,bold,bolditalic" rel="stylesheet" />
  268.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Droid serif', serif;}</style>
  269.     <?php } elseif(get_option("ct_font", true) =="goudy bookletter") { ?>
  270.         <link  href="http://fonts.googleapis.com/css?family=Goudy+Bookletter+1911:regular" rel="stylesheet" />
  271.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Goudy Bookletter 1911', serif;}</style>
  272.     <?php } elseif(get_option("ct_font", true) =="pacifico") { ?>
  273.         <link  href="http://fonts.googleapis.com/css?family=Pacifico:regular" rel="stylesheet" />
  274.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Pacifico', serif;}</style>
  275.     <?php } elseif(get_option("ct_font", true) =="pacifico") { ?>
  276.         <link  href="http://fonts.googleapis.com/css?family=Amaranth:regular" rel="stylesheet" />
  277.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Amaranth', serif;}</style>
  278.     <?php } elseif(get_option("ct_font", true) =="allerta") { ?>  
  279.         <link  href="http://fonts.googleapis.com/css?family=Allerta:regular" rel="stylesheet" >
  280.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Allerta', serif;}</style>
  281.     <?php } elseif(get_option("ct_font", true) =="crushed") { ?>  
  282.         <link  href="http://fonts.googleapis.com/css?family=Crushed:regular" rel="stylesheet" >
  283.         <style>h1,h2,h3,h4,h5,h6 { font-family: 'Crushed', serif;}</style>
  284.     <?php } elseif(get_option("ct_font", true) =="defaultstack") {}
  285.    
  286.     // Date format
  287.     $GLOBALS['ctdate'] = get_option('ct_dateformat');  
  288.     if ( $GLOBALS['ctdate'] == "" )
  289.         $GLOBALS['ctdate'] = "M j, Y"; 
  290.  
  291. }
  292.  
  293. // Contact Us Validation
  294. function contact_us_validation() { ?>
  295.     <!-- Contact Form Validation and Ajax Submit -->
  296.     <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/validationEngine.jquery.css" media="screen" charset="utf-8" />
  297.     <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.validationEngine.js"></script>
  298.     <script>
  299.     // Ajax Submit
  300.     // Full documentation on this can be found at http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
  301.     jQuery(document).ready(function() {
  302.         jQuery("#contactform").validationEngine({
  303.             ajaxSubmit: true,
  304.                 ajaxSubmitFile: "<?php echo get_template_directory_uri(); ?>/includes/ajaxSubmit.php",
  305.                 ajaxSubmitMessage: "<?php echo stripslashes(get_option("ct_success", true)); ?>",
  306.             success :  false,
  307.             failure : function() {}
  308.         })
  309.     });
  310.     </script>
  311. <?php }
  312.  
  313. // Contact Us Map
  314. function contact_us_map() {
  315.     if(get_option("ct_gmap", true) =="yes") { ?>    
  316.         <script src="http://maps.google.com/maps/api/js?sensor=false"></script>    
  317.         <script>
  318.         function setMapAddress(address) {
  319.             var geocoder = new google.maps.Geocoder();
  320.             geocoder.geocode( { address : address }, function( results, status ) {
  321.                 if( status == google.maps.GeocoderStatus.OK ) {
  322.                     var location = results[0].geometry.location;
  323.                     var options = {
  324.                         zoom: 15,
  325.                         center: location,
  326.                         mapTypeId: google.maps.MapTypeId.<?php echo get_option("ct_gmap_type", true); ?>,
  327.                         streetViewControl: true
  328.                     };
  329.                     var mymap = new google.maps.Map( document.getElementById( 'map' ), options );  
  330.                     var marker = new google.maps.Marker({
  331.                     map: mymap,
  332.                     position: results[0].geometry.location
  333.                 });    
  334.                 }
  335.             } );
  336.         }
  337.         setMapAddress( "<?php echo get_option("ct_address", true); ?>" );
  338.         </script>
  339.         <div id="location" class="onethirdcol left last">
  340.             <?php if(get_option("ct_companyinfo", true) !="") { ?>
  341.                 <?php echo stripslashes(get_option("ct_companyinfo", true)); ?>
  342.             <?php } ?>
  343.             <div id="map" class="left">Loading...</div>
  344.         </div>
  345.     <?php }
  346. }
  347.  
  348. // Required footer credit for Museo typeface
  349. function footer_font_credit () {
  350.     if(get_option("ct_font", true) =="museosans") { ?>
  351.     Museo Font by <a href="http://www.exljbris.com">Jos Buivenga</a>.
  352.     <?php } elseif(get_option("ct_font", true) =="museoslab") { ?>
  353.     Museo Font by <a href="http://www.exljbris.com">Jos Buivenga</a>.
  354.     <?php }
  355. }
  356.  
  357. /*-----------------------------------------------------------------------------------*/
  358. /* Demo Changer */
  359. /*-----------------------------------------------------------------------------------*/
  360.  
  361. function ct_demo_head() {
  362.     require_once(STYLESHEETPATH . '/demo/demo-styles.php');
  363. }
  364.  
  365. function ct_demo_footer() {
  366.     require_once(STYLESHEETPATH . '/demo/demo-styles-footer.php'); 
  367. }
  368.  
  369. // Remove WLW and RSD for validation
  370. remove_action('wp_head', 'wlwmanifest_link');
  371. remove_action('wp_head', 'rsd_link');
  372.  
  373. // Tags Navigation for Product & Portfolio
  374. function ct_tags_nav() { ?>
  375. <ul id="tags-nav" class="clear">
  376.     <li id="select"><?php _e('Filter:', 'contempo'); ?></li>
  377.     <li><a href="#" class="all"><?php _e('All','contempo'); ?></a></li>
  378.     <?php
  379.     if(is_post_type_archive('portfolio')) {
  380.         $terms = get_terms('portfolio_tags');
  381.     } elseif(is_post_type_archive('products')) {
  382.         $terms = get_terms('product_tags');
  383.     }
  384.     $count = count($terms);
  385.     if ( $count > 0 ){
  386.         foreach ( $terms as $term ) {
  387.             echo "<li><a href='#' class='$term->slug'>" . $term->name . "</a></li>";            
  388.          }
  389.      } ?>
  390. </ul>
  391. <?php }
  392.  
  393. // Output all term slugs
  394. function ct_terms() {
  395.     if(is_post_type_archive('portfolio')) {
  396.         $terms = get_the_terms( $post->id, 'portfolio_tags' );
  397.     } elseif(is_post_type_archive('products')) {
  398.         $terms = get_the_terms( $post->id, 'product_tags' );
  399.     }
  400.     if ($terms) {
  401.         foreach($terms as $term) {
  402.             echo $term->slug;
  403.         }
  404.     }
  405. }
  406.  
  407. // Show the first term name only
  408. function ct_first_term() {
  409.     if(is_post_type_archive('portfolio')) {
  410.         $terms = get_the_terms( $post->id, 'portfolio_tags' );
  411.     } elseif(is_post_type_archive('products')) {
  412.         $terms = get_the_terms( $post->id, 'product_tags' );
  413.     }
  414.     $count = 0;
  415.     if ($terms) {
  416.         foreach($terms as $term) {
  417.             $count++;
  418.             if (1 == $count) {
  419.                 echo $term->name;
  420.             }
  421.         }
  422.     }
  423. }
  424.  
  425. // Access post data outside the loop
  426. function get_post_data($postId) {
  427.     global $wpdb;
  428.     return $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID=$postId");
  429. }
  430.  
  431. // Custom Excerpt Length
  432. function new_excerpt_length($length) {
  433.     $exlength = get_option("ct_excerpt_length", true);
  434.     return $exlength;
  435. }
  436. add_filter('excerpt_length', 'new_excerpt_length');
  437.  
  438. // Remove <p> tags from the_excerpt
  439. remove_filter('the_excerpt', 'wpautop');
  440.  
  441. // Allow Shortcodes to be used in widgets
  442. add_filter('widget_text', 'do_shortcode');
  443.  
  444. // Pagination
  445. function ct_pagination($pages = '', $range = 2) {  
  446.      $showitems = ($range * 2)+1;  
  447.  
  448.      global $paged;
  449.      if(empty($paged)) $paged = 1;
  450.  
  451.      if($pages == '') {
  452.          global $wp_query;
  453.          $pages = $wp_query->max_num_pages;
  454.          if(!$pages) {
  455.              $pages = 1;
  456.          }
  457.      }  
  458.  
  459.      if(1 != $pages) {
  460.          echo "<div class='pagination clear'>";
  461.          if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
  462.          if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";
  463.  
  464.          for ($i=1; $i <= $pages; $i++)
  465.          {
  466.              if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  467.              {
  468.                  echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
  469.              }
  470.          }
  471.  
  472.          if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";  
  473.          if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
  474.          echo "<div class='clear'></div>\n";
  475.          echo "</div>\n";
  476.      }
  477. }
  478.  
  479. // Get all of the images attached to the current post
  480. function ct_get_images($size = 'full') {
  481.     global $post;
  482.     $photos = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
  483.     $results = array();
  484.     if ($photos) {
  485.         foreach ($photos as $photo) {
  486.             // get the correct image html for the selected size
  487.             $results[] = wp_get_attachment_url($photo->ID);
  488.         }
  489.     }
  490.     return $results;
  491. }
  492.  
  493. // Display all images attached to listing - homepage featured
  494. function ct_featured_images() {
  495.     $photos = ct_get_images('full');
  496.     if ($photos) {
  497.         foreach ($photos as $photo) { ?>
  498.             <img src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo $photo ?>&amp;h=348&amp;w=916&amp;zc=1" title="<?php the_title(); ?>" />
  499.         <?php }
  500.     }  
  501. }
  502.  
  503. // Display all images attached to portfolio - detail
  504. function ct_portfolio_images() {
  505.     $photos = ct_get_images('full');
  506.     if ($photos) {
  507.         foreach ($photos as $photo) { ?>
  508.             <img class="lead" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo $photo ?>&amp;h=430&amp;w=583&amp;zc=1" />
  509.         <?php }
  510.     }  
  511. }
  512.  
  513. // Display all images attached to client portfolio
  514. function ct_client_logos() {
  515.     $photos = ct_get_images('full');
  516.     if ($photos) {
  517.         foreach ($photos as $photo) { ?>
  518.         <div class="client-logo imgwraptn left">
  519.             <a href="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo $photo ?>&amp;w=500&amp;zc=1" rel="prettyPhoto[clients]">
  520.                 <img class="tn imgfade" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo $photo ?>&amp;h=68&amp;w=118&amp;zc=1" />
  521.             </a>
  522.         </div>
  523.         <?php }
  524.     }  
  525. }
  526.  
  527. //Get the first image attached to the current post
  528. function ct_get_post_image() {
  529.     global $post;
  530.     $photos = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
  531.     if ($photos) {
  532.         $photo = array_shift($photos);
  533.         return wp_get_attachment_url($photo->ID);
  534.     }
  535.     return false;
  536. }
  537.  
  538. // Display first image thumbnail
  539. function ct_first_image_tn() {
  540.     $photo = ct_get_post_image();
  541.     if ($photo) { ?>
  542.     <div class="imgwraptn">
  543.         <a href="<?php the_permalink(); ?>"><img class="tn imgfade" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;h=40&amp;w=69&amp;zc=1" /></a>
  544.     </div>
  545.     <?php }
  546. }
  547.  
  548. // Display first image thumbnail - float left
  549. function ct_first_image_tn_left() {
  550.     $photo = ct_get_post_image();
  551.     if ($photo) { ?>
  552.     <div class="imgwraptn left">
  553.         <a href="<?php the_permalink(); ?>"><img class="tn left imgfade" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;h=40&amp;w=69&amp;zc=1" /></a>
  554.     </div>
  555.     <?php }
  556. }
  557.  
  558. // Display first image thumbnail - float right
  559. function ct_first_image_tn_right() {
  560.     $photo = ct_get_post_image();
  561.     if ($photo) { ?>
  562.     <div class="imgwraptn right">
  563.         <a href="<?php the_permalink(); ?>"><img class="tn right imgfade" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;h=40&amp;w=69&amp;zc=1" /></a>
  564.     </div>
  565.     <?php }
  566. }
  567.  
  568. // Display first image headshot for testimonial widget
  569. function ct_first_image_headshot() {
  570.     $photo = ct_get_post_image();
  571.     if ($photo) { ?>
  572.     <div class="imgwrapheadshot right">
  573.         <img class="tn imgfade" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;h=54&amp;w=40&amp;zc=1" />
  574.     </div>
  575.     <?php }
  576. }
  577.  
  578. // Display first image headshot for testimonial widget
  579. function ct_first_image_headshot_left() {
  580.     $photo = ct_get_post_image();
  581.     if ($photo) { ?>
  582.     <div class="imgwrapheadshot left">
  583.         <img class="tn imgfade" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;h=54&amp;w=40&amp;zc=1" />
  584.     </div>
  585.     <?php }
  586. }
  587.  
  588. function ct_first_image_headshot_lrg() {
  589.     $photo = ct_get_post_image();
  590.     if ($photo) { ?>
  591.     <div class="imgwrapheadshotlrg right">
  592.         <img class="tn imgfade" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;h=95&amp;w=70&amp;zc=1" />
  593.     </div>
  594.     <?php }
  595. }
  596.  
  597. // Display first image medium
  598. function ct_first_image_md() {
  599.     $photo = ct_get_post_image();
  600.     if ($photo) { ?>
  601.     <div class="imgwrapmd">
  602.         <?php if(!is_single()) { ?>
  603.         <a href="<?php the_permalink(); ?>">
  604.         <?php } ?>
  605.             <span class="overlay"></span>
  606.             <img class="med imgfade" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;h=163&amp;w=272&amp;zc=1" />
  607.         <?php if(!is_single()) { ?>
  608.         </a>
  609.         <?php } ?>
  610.     </div>
  611.     <?php }
  612. }
  613.  
  614. // Display first image blog archive
  615. function ct_first_image_blog() {
  616.     $photo = ct_get_post_image();
  617.     if ($photo) { ?>
  618.     <div class="imgwraplead">
  619.         <a href="<?php if(is_single()) { ?><?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;w=800&amp;zc=1<?php } else { ?><?php the_permalink(); ?><?php } ?>" <?php if(is_single()) { ?>rel="prettyPhoto"<?php } ?>><img class="lead imgfade" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;h=240&amp;w=583&amp;zc=1" /></a>
  620.     </div>
  621.     <?php }
  622. }
  623.  
  624. // Display first image portfolio
  625. function ct_first_image_portfolio() {
  626.     $photo = ct_get_post_image();
  627.     if ($photo) { ?>
  628.     <div class="imgwrapportfolio left">
  629.         <a href="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;w=800&amp;zc=1" rel="prettyPhoto[portfolio]" title="<?php the_excerpt(); ?>">
  630.             <img class="lead imgfade" src="<?php echo get_template_directory_uri(); ?>/img_resize/timthumb.php?src=<?php echo ct_get_post_image() ?>&amp;h=430&amp;w=583&amp;zc=1" />
  631.         </a>
  632.     </div>
  633.     <?php }
  634. }
  635.  
  636. // Get users
  637. function ct_get_users($users_per_page = 10, $paged = 1, $role = '', $orderby = 'login', $order = 'ASC', $usersearch = '' ) {
  638.  
  639.     global $blog_id;
  640.        
  641.     $args = array(
  642.             'number' => $users_per_page,
  643.             'offset' => ( $paged-1 ) * $users_per_page,
  644.             'role' => $role,
  645.             'search' => $usersearch,
  646.             'fields' => 'all_with_meta',
  647.             'blog_id' => $blog_id,
  648.             'orderby' => $orderby,
  649.             'order' => $order
  650.         );
  651.  
  652.     $wp_user_search = new WP_User_Query( $args );
  653.     $user_results = $wp_user_search->get_results();
  654.    
  655.     return $user_results;
  656.    
  657. }
  658.  
  659. /**
  660.  * The code below is inspired by Justin Tadlock's Hybrid Core.
  661.  *
  662.  * ct_breadcrumbs() shows a breadcrumb for all types of pages.  Themes and plugins can filter $args or input directly.
  663.  * Allow filtering of only the $args using get_the_breadcrumb_args.
  664.  *
  665.  * @since 3.7.0
  666.  * @param array $args Mixed arguments for the menu.
  667.  * @return string Output of the breadcrumb menu.
  668.  */
  669. function ct_breadcrumbs( $args = array() ) {
  670.     global $wp_query, $wp_rewrite;
  671.  
  672.     /* Get the textdomain. */
  673.     $textdomain = 'contempo';
  674.  
  675.     /* Create an empty variable for the breadcrumb. */
  676.     $breadcrumb = '';
  677.  
  678.     /* Create an empty array for the trail. */
  679.     $trail = array();
  680.     $path = '';
  681.  
  682.     /* Set up the default arguments for the breadcrumb. */
  683.     $defaults = array(
  684.         'separator' => '&raquo;',
  685.         'before' => '<span class="breadcrumb-title"></span>',
  686.         'after' => false,
  687.         'front_page' => true,
  688.         'show_home' => __( 'Home', $textdomain ),
  689.         'echo' => true
  690.     );
  691.  
  692.     /* Allow singular post views to have a taxonomy's terms prefixing the trail. */
  693.     if ( is_singular() )
  694.         $defaults["singular_{$wp_query->post->post_type}_taxonomy"] = false;
  695.  
  696.     /* Apply filters to the arguments. */
  697.     $args = apply_filters( 'ct_breadcrumbs_args', $args );
  698.  
  699.     /* Parse the arguments and extract them for easy variable naming. */
  700.     extract( wp_parse_args( $args, $defaults ) );
  701.  
  702.     /* If $show_home is set and we're not on the front page of the site, link to the home page. */
  703.     if ( !is_front_page() && $show_home )
  704.         $trail[] = '<a href="' . home_url() . '" title="' . esc_attr( get_bloginfo( 'name' ) ) . '" rel="home" class="trail-begin">' . $show_home . '</a>';
  705.  
  706.     /* If viewing the front page of the site. */
  707.     if ( is_front_page() ) {
  708.         if ( !$front_page )
  709.             $trail = false;
  710.         elseif ( $show_home )
  711.             $trail['trail_end'] = "{$show_home}";
  712.     }
  713.  
  714.     /* If viewing the "home"/posts page. */
  715.     elseif ( is_home() ) {
  716.         $home_page = get_page( $wp_query->get_queried_object_id() );
  717.         $trail = array_merge( $trail, ct_breadcrumbs_get_parents( $home_page->post_parent, '' ) );
  718.         $trail['trail_end'] = get_the_title( $home_page->ID );
  719.     }
  720.  
  721.     /* If viewing a singular post (page, attachment, etc.). */
  722.     elseif ( is_singular() ) {
  723.  
  724.         /* Get singular post variables needed. */
  725.         $post = $wp_query->get_queried_object();
  726.         $post_id = absint( $wp_query->get_queried_object_id() );
  727.         $post_type = $post->post_type;
  728.         $parent = $post->post_parent;
  729.  
  730.         /* If a custom post type, check if there are any pages in its hierarchy based on the slug. */
  731.         if ( 'page' !== $post_type ) {
  732.  
  733.             $post_type_object = get_post_type_object( $post_type );
  734.  
  735.             /* If $front has been set, add it to the $path. */
  736.             if ( 'post' == $post_type || 'attachment' == $post_type || ( $post_type_object->rewrite['with_front'] && $wp_rewrite->front ) )
  737.                 $path .= trailingslashit( $wp_rewrite->front );
  738.  
  739.             /* If there's a slug, add it to the $path. */
  740.             if ( !empty( $post_type_object->rewrite['slug'] ) )
  741.                 $path .= $post_type_object->rewrite['slug'];
  742.  
  743.             /* If there's a path, check for parents. */
  744.             if ( !empty( $path ) )
  745.                 $trail = array_merge( $trail, ct_breadcrumbs_get_parents( '', $path ) );
  746.  
  747.             /* If there's an archive page, add it to the trail. */
  748.             if ( !empty( $post_type_object->rewrite['archive'] ) && function_exists( 'get_post_type_archive_link' ) )
  749.                 $trail[] = '<a href="' . get_post_type_archive_link( $post_type ) . '" title="' . esc_attr( $post_type_object->labels->name ) . '">' . $post_type_object->labels->name . '</a>';
  750.         }
  751.  
  752.         /* If the post type path returns nothing and there is a parent, get its parents. */
  753.         if ( empty( $path ) && 0 !== $parent || 'attachment' == $post_type )
  754.             $trail = array_merge( $trail, ct_breadcrumbs_get_parents( $parent, '' ) );
  755.  
  756.         /* Display terms for specific post type taxonomy if requested. */
  757.         if ( isset( $args["singular_{$post_type}_taxonomy"] ) && $terms = get_the_term_list( $post_id, $args["singular_{$post_type}_taxonomy"], '', ', ', '' ) )
  758.             $trail[] = $terms;
  759.  
  760.         /* End with the post title. */
  761.         $post_title = get_the_title( $post_id ); // Force the post_id to make sure we get the correct page title.
  762.         if ( !empty( $post_title ) )
  763.             $trail['trail_end'] = $post_title;
  764.     }
  765.  
  766.     /* If we're viewing any type of archive. */
  767.     elseif ( is_archive() ) {
  768.  
  769.         /* If viewing a taxonomy term archive. */
  770.         if ( is_tax() || is_category() || is_tag() ) {
  771.  
  772.             /* Get some taxonomy and term variables. */
  773.             $term = $wp_query->get_queried_object();
  774.             $taxonomy = get_taxonomy( $term->taxonomy );
  775.  
  776.             /* Get the path to the term archive. Use this to determine if a page is present with it. */
  777.             if ( is_category() )
  778.                 $path = get_option( 'category_base' );
  779.             elseif ( is_tag() )
  780.                 $path = get_option( 'tag_base' );
  781.             else {
  782.                 if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front )
  783.                     $path = trailingslashit( $wp_rewrite->front );
  784.                 $path .= $taxonomy->rewrite['slug'];
  785.             }
  786.  
  787.             /* Get parent pages by path if they exist. */
  788.             if ( $path )
  789.                 $trail = array_merge( $trail, ct_breadcrumbs_get_parents( '', $path ) );
  790.  
  791.             /* If the taxonomy is hierarchical, list its parent terms. */
  792.             if ( is_taxonomy_hierarchical( $term->taxonomy ) && $term->parent )
  793.                 $trail = array_merge( $trail, ct_breadcrumbs_get_term_parents( $term->parent, $term->taxonomy ) );
  794.  
  795.             /* Add the term name to the trail end. */
  796.             $trail['trail_end'] = $term->name;
  797.         }
  798.  
  799.         /* If viewing a post type archive. */
  800.         elseif ( function_exists( 'is_post_type_archive' ) && is_post_type_archive() ) {
  801.  
  802.             /* Get the post type object. */
  803.             $post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
  804.  
  805.             /* If $front has been set, add it to the $path. */
  806.             if ( $post_type_object->rewrite['with_front'] && $wp_rewrite->front )
  807.                 $path .= trailingslashit( $wp_rewrite->front );
  808.  
  809.             /* If there's a slug, add it to the $path. */
  810.             if ( !empty( $post_type_object->rewrite['archive'] ) )
  811.                 $path .= $post_type_object->rewrite['archive'];
  812.  
  813.             /* If there's a path, check for parents. */
  814.             if ( !empty( $path ) )
  815.                 $trail = array_merge( $trail, ct_breadcrumbs_get_parents( '', $path ) );
  816.  
  817.             /* Add the post type [plural] name to the trail end. */
  818.             $trail['trail_end'] = $post_type_object->labels->name;
  819.         }
  820.  
  821.         /* If viewing an author archive. */
  822.         elseif ( is_author() ) {
  823.  
  824.             /* If $front has been set, add it to $path. */
  825.             if ( !empty( $wp_rewrite->front ) )
  826.                 $path .= trailingslashit( $wp_rewrite->front );
  827.  
  828.             /* If an $author_base exists, add it to $path. */
  829.             if ( !empty( $wp_rewrite->author_base ) )
  830.                 $path .= $wp_rewrite->author_base;
  831.  
  832.             /* If $path exists, check for parent pages. */
  833.             if ( !empty( $path ) )
  834.                 $trail = array_merge( $trail, ct_breadcrumbs_get_parents( '', $path ) );
  835.  
  836.             /* Add the author's display name to the trail end. */
  837.             $trail['trail_end'] = get_the_author_meta( 'display_name', get_query_var( 'author' ) );
  838.         }
  839.  
  840.         /* If viewing a time-based archive. */
  841.         elseif ( is_time() ) {
  842.  
  843.             if ( get_query_var( 'minute' ) && get_query_var( 'hour' ) )
  844.                 $trail['trail_end'] = get_the_time( __( 'g:i a', $textdomain ) );
  845.  
  846.             elseif ( get_query_var( 'minute' ) )
  847.                 $trail['trail_end'] = sprintf( __( 'Minute %1$s', $textdomain ), get_the_time( __( 'i', $textdomain ) ) );
  848.  
  849.             elseif ( get_query_var( 'hour' ) )
  850.                 $trail['trail_end'] = get_the_time( __( 'g a', $textdomain ) );
  851.         }
  852.  
  853.         /* If viewing a date-based archive. */
  854.         elseif ( is_date() ) {
  855.  
  856.             /* If $front has been set, check for parent pages. */
  857.             if ( $wp_rewrite->front )
  858.                 $trail = array_merge( $trail, ct_breadcrumbs_get_parents( '', $wp_rewrite->front ) );
  859.  
  860.             if ( is_day() ) {
  861.                 $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>';
  862.                 $trail[] = '<a href="' . get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) . '" title="' . get_the_time( esc_attr__( 'F', $textdomain ) ) . '">' . get_the_time( __( 'F', $textdomain ) ) . '</a>';
  863.                 $trail['trail_end'] = get_the_time( __( 'j', $textdomain ) );
  864.             }
  865.  
  866.             elseif ( get_query_var( 'w' ) ) {
  867.                 $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>';
  868.                 $trail['trail_end'] = sprintf( __( 'Week %1$s', $textdomain ), get_the_time( esc_attr__( 'W', $textdomain ) ) );
  869.             }
  870.  
  871.             elseif ( is_month() ) {
  872.                 $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>';
  873.                 $trail['trail_end'] = get_the_time( __( 'F', $textdomain ) );
  874.             }
  875.  
  876.             elseif ( is_year() ) {
  877.                 $trail['trail_end'] = get_the_time( __( 'Y', $textdomain ) );
  878.             }
  879.         }
  880.     }
  881.  
  882.     /* If viewing search results. */
  883.     elseif ( is_search() )
  884.         $trail['trail_end'] = sprintf( __( 'Search results for &quot;%1$s&quot;', $textdomain ), esc_attr( get_search_query() ) );
  885.  
  886.     /* If viewing a 404 error page. */
  887.     elseif ( is_404() )
  888.         $trail['trail_end'] = __( '404 Not Found', $textdomain );
  889.  
  890.     /* Connect the breadcrumb trail if there are items in the trail. */
  891.     if ( is_array( $trail ) ) {
  892.  
  893.         /* Open the breadcrumb trail containers. */
  894.         $breadcrumb = '<div class="breadcrumb breadcrumbs ct-breadcrumbs"><div class="breadcrumb-trail">';
  895.  
  896.         /* If $before was set, wrap it in a container. */
  897.         if ( !empty( $before ) )
  898.             $breadcrumb .= '<span class="trail-before">' . $before . '</span> ';
  899.  
  900.         /* Wrap the $trail['trail_end'] value in a container. */
  901.         if ( !empty( $trail['trail_end'] ) )
  902.             $trail['trail_end'] = '<span class="trail-end">' . $trail['trail_end'] . '</span>';
  903.  
  904.         /* Format the separator. */
  905.         if ( !empty( $separator ) )
  906.             $separator = '<span class="sep">' . $separator . '</span>';
  907.  
  908.         /* Join the individual trail items into a single string. */
  909.         $breadcrumb .= join( " {$separator} ", $trail );
  910.  
  911.         /* If $after was set, wrap it in a container. */
  912.         if ( !empty( $after ) )
  913.             $breadcrumb .= ' <span class="trail-after">' . $after . '</span>';
  914.  
  915.         /* Close the breadcrumb trail containers. */
  916.         $breadcrumb .= '</div></div>';
  917.     }
  918.  
  919.     /* Allow developers to filter the breadcrumb trail HTML. */
  920.     $breadcrumb = apply_filters( 'ct_breadcrumbs', $breadcrumb );
  921.  
  922.     /* Output the breadcrumb. */
  923.     if ( $echo )
  924.         echo $breadcrumb;
  925.     else
  926.         return $breadcrumb;
  927.  
  928. }
  929.  
  930. // Get Parents
  931. function ct_breadcrumbs_get_parents( $post_id = '', $path = '' ) {
  932.  
  933.     /* Set up an empty trail array. */
  934.     $trail = array();
  935.  
  936.     /* If neither a post ID nor path set, return an empty array. */
  937.     if ( empty( $post_id ) && empty( $path ) )
  938.         return $trail;
  939.  
  940.     /* If the post ID is empty, use the path to get the ID. */
  941.     if ( empty( $post_id ) ) {
  942.  
  943.         /* Get parent post by the path. */
  944.         $parent_page = get_page_by_path( $path );
  945.  
  946.         if( empty( $parent_page ) )
  947.                 // search on page name (single word)
  948.             $parent_page = get_page_by_title ( $path );
  949.  
  950.         if( empty( $parent_page ) )
  951.             // search on page title (multiple words)
  952.             $parent_page = get_page_by_title ( str_replace( array('-', '_'), ' ', $path ) );
  953.  
  954.         /* End Modification */
  955.  
  956.         /* If a parent post is found, set the $post_id variable to it. */
  957.         if ( !empty( $parent_page ) )
  958.             $post_id = $parent_page->ID;
  959.     }
  960.  
  961.     /* If a post ID and path is set, search for a post by the given path. */
  962.     if ( $post_id == 0 && !empty( $path ) ) {
  963.  
  964.         /* Separate post names into separate paths by '/'. */
  965.         $path = trim( $path, '/' );
  966.         preg_match_all( "/\/.*?\z/", $path, $matches );
  967.  
  968.         /* If matches are found for the path. */
  969.         if ( isset( $matches ) ) {
  970.  
  971.             /* Reverse the array of matches to search for posts in the proper order. */
  972.             $matches = array_reverse( $matches );
  973.  
  974.             /* Loop through each of the path matches. */
  975.             foreach ( $matches as $match ) {
  976.  
  977.                 /* If a match is found. */
  978.                 if ( isset( $match[0] ) ) {
  979.  
  980.                     /* Get the parent post by the given path. */
  981.                     $path = str_replace( $match[0], '', $path );
  982.                     $parent_page = get_page_by_path( trim( $path, '/' ) );
  983.  
  984.                     /* If a parent post is found, set the $post_id and break out of the loop. */
  985.                     if ( !empty( $parent_page ) && $parent_page->ID > 0 ) {
  986.                         $post_id = $parent_page->ID;
  987.                         break;
  988.                     }
  989.                 }
  990.             }
  991.         }
  992.     }
  993.  
  994.     /* While there's a post ID, add the post link to the $parents array. */
  995.     while ( $post_id ) {
  996.  
  997.         /* Get the post by ID. */
  998.         $page = get_page( $post_id );
  999.  
  1000.         /* Add the formatted post link to the array of parents. */
  1001.         $parents[]  = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . get_the_title( $post_id ) . '</a>';
  1002.  
  1003.         /* Set the parent post's parent to the post ID. */
  1004.         $post_id = $page->post_parent;
  1005.     }
  1006.  
  1007.     /* If we have parent posts, reverse the array to put them in the proper order for the trail. */
  1008.     if ( isset( $parents ) )
  1009.         $trail = array_reverse( $parents );
  1010.  
  1011.     /* Return the trail of parent posts. */
  1012.     return $trail;
  1013.  
  1014. }
  1015.  
  1016. // Get Term Parents
  1017. function ct_breadcrumbs_get_term_parents( $parent_id = '', $taxonomy = '' ) {
  1018.  
  1019.     /* Set up some default arrays. */
  1020.     $trail = array();
  1021.     $parents = array();
  1022.  
  1023.     /* If no term parent ID or taxonomy is given, return an empty array. */
  1024.     if ( empty( $parent_id ) || empty( $taxonomy ) )
  1025.         return $trail;
  1026.  
  1027.     /* While there is a parent ID, add the parent term link to the $parents array. */
  1028.     while ( $parent_id ) {
  1029.  
  1030.         /* Get the parent term. */
  1031.         $parent = get_term( $parent_id, $taxonomy );
  1032.  
  1033.         /* Add the formatted term link to the array of parent terms. */
  1034.         $parents[] = '<a href="' . get_term_link( $parent, $taxonomy ) . '" title="' . esc_attr( $parent->name ) . '">' . $parent->name . '</a>';
  1035.  
  1036.         /* Set the parent term's parent as the parent ID. */
  1037.         $parent_id = $parent->parent;
  1038.     }
  1039.  
  1040.     /* If we have parent terms, reverse the array to put them in the proper order for the trail. */
  1041.     if ( !empty( $parents ) )
  1042.         $trail = array_reverse( $parents );
  1043.  
  1044.     /* Return the trail of parent terms. */
  1045.     return $trail;
  1046.  
  1047. } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement