Advertisement
justrjlewis

template-tags

May 31st, 2016
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.21 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Custom template tags for this theme.
  4.  *
  5.  * Eventually, some of the functionality here could be replaced by core features.
  6.  *
  7.  * @package Accesspress Mag Pro
  8.  */
  9.  
  10. if ( ! function_exists( 'accesspress_mag_paging_nav' ) ) :
  11. /**
  12.  * Display navigation to next/previous set of posts when applicable.
  13.  *
  14.  * @todo Remove this function when WordPress 4.3 is released.
  15.  */
  16. function accesspress_mag_paging_nav() {
  17.     // Don't print empty markup if there's only one page.
  18.     if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
  19.         return;
  20.     }
  21.     ?>
  22.     <nav class="navigation posts-navigation clearfix" role="navigation">
  23.         <h2 class="screen-reader-text"><?php _e( 'Posts navigation', 'accesspress-mag' ); ?></h2>
  24.         <div class="nav-links">
  25.  
  26.             <?php if ( get_next_posts_link() ) : ?>
  27.             <div class="nav-previous"><i class="fa fa-angle-left"></i><?php next_posts_link( __( 'Older posts', 'accesspress-mag' ) ); ?></div>
  28.             <?php endif; ?>
  29.  
  30.             <?php if ( get_previous_posts_link() ) : ?>
  31.             <div class="nav-next"><?php previous_posts_link( __( 'Newer posts', 'accesspress-mag' ) ); ?><i class="fa fa-angle-right"></i></div>
  32.             <?php endif; ?>
  33.  
  34.         </div><!-- .nav-links -->
  35.     </nav><!-- .navigation -->
  36.     <?php
  37. }
  38. endif;
  39.  
  40. if ( ! function_exists( 'accesspress_mag_post_navigation' ) ) :
  41. /**
  42.  * Display navigation to next/previous post when applicable.
  43.  *
  44.  * @todo Remove this function when WordPress 4.3 is released.
  45.  */
  46. function accesspress_mag_post_navigation() {
  47.     $trans_next = of_get_option( 'trans_next_article' );
  48.     if( empty( $trans_next ) ){ $trans_next = __( 'Next article', 'accesspress-mag' ); }
  49.     $trans_prev = of_get_option( 'trans_previous_article' );
  50.     if( empty( $trans_prev ) ){ $trans_prev = __( 'Previous article', 'accesspress-mag' ) ; }
  51.     // Don't print empty markup if there's nowhere to navigate.
  52.     $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
  53.     $next     = get_adjacent_post( false, '', false );
  54.  
  55.     if ( ! $next && ! $previous ) {
  56.         return;
  57.     }
  58.     ?>
  59.     <nav class="navigation post-navigation clearfix" role="navigation">
  60.         <h2 class="screen-reader-text"><?php _e( 'Post navigation', 'accesspress-mag' ); ?></h2>
  61.         <div class="nav-links">
  62.             <?php
  63.                 previous_post_link( '<div class="nav-previous"><div class="link-caption"><i class="fa fa-angle-left"></i>'.esc_attr( $trans_prev ).'</div>%link</div>', '%title' );
  64.                 next_post_link( '<div class="nav-next"><div class="link-caption">'.esc_attr( $trans_next ).'<i class="fa fa-angle-right"></i></div>%link</div>', '%title' );
  65.             ?>
  66.         </div><!-- .nav-links -->
  67.     </nav><!-- .navigation -->
  68.     <?php
  69. }
  70. endif;
  71.  
  72. if ( ! function_exists( 'accesspress_mag_posted_on' ) ) :
  73. /**
  74.  * Prints HTML with meta information for the current post-date/time and author.
  75.  */
  76. function accesspress_mag_posted_on() {
  77.     $show_post_date = of_get_option('post_show_date');
  78.     $show_author = of_get_option('show_author_name');
  79.    
  80.     $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  81.     if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  82.         $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
  83.     }
  84.  
  85.     $time_string = sprintf( $time_string,
  86.         esc_attr( get_the_date( 'c' ) ),
  87.         esc_html( get_the_date() ),
  88.         esc_attr( get_the_modified_date( 'c' ) ),
  89.         esc_html( get_the_modified_date() )
  90.     );
  91.    
  92.     if($show_post_date==1){
  93.       $posted_on = sprintf(
  94.             _x( '%s', 'post date', 'accesspress-mag' ),$time_string
  95.            
  96.             //'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
  97.         );     
  98.     } else {
  99.         $posted_on = '';
  100.     }
  101.    
  102.    
  103.     if($show_author==1){
  104.         $byline = sprintf(
  105.             _x( 'by %s', 'post author', 'accesspress-mag' ),
  106.             '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
  107.         );
  108.     } else {
  109.         $byline='';
  110.     }  
  111.  
  112.     echo '<span class="byline"> ' . $byline . ' - </span><span class="posted-on">' . $posted_on . '</span>';
  113.  
  114. }
  115. endif;
  116.  
  117. if ( ! function_exists( 'accesspress_mag_entry_footer' ) ) :
  118. /**
  119.  * Prints HTML with meta information for the categories, tags and comments.
  120.  */
  121. function accesspress_mag_entry_footer() {
  122.     if( 'post' == get_post_type() && is_single() ) {
  123.         global $post;
  124.         // Hide category and tag text for pages.
  125.         $trans_via = of_get_option( 'trans_via' );
  126.         if( empty( $trans_via ) ){ $trans_via = 'Via'; }
  127.         $trans_source = of_get_option( 'trans_source' );
  128.         if( empty( $trans_source ) ){ $trans_source = 'Source'; }
  129.         $post_source_name   = get_post_meta($post->ID, 'post_source_name', true);
  130.         $post_source_url    = get_post_meta($post->ID, 'post_source_url', true);
  131.         $post_via_name      = get_post_meta($post->ID, 'post_via_name', true);
  132.         $post_via_url       = get_post_meta($post->ID, 'post_via_url', true);
  133.         if( !empty( $post_via_name ) ) {
  134.         ?>
  135.             <div class="post-via-wrapper">
  136.                 <label class="via"><?php echo esc_attr( $trans_via );?></label>
  137.                 <a href="<?php echo esc_attr( $post_via_url );?>" target="_blank">
  138.                     <span class="via-name"><?php echo esc_attr( $post_via_name ); ?></span>
  139.                 </a>
  140.             </div><!-- .post-via-wrapper -->
  141.         <?php
  142.         }
  143.         if( !empty( $post_source_name ) ) {
  144.         ?>
  145.             <div class="post-source-wrapper">
  146.                 <label class="source"><?php echo esc_attr( $trans_source  ) ;?></label>
  147.                 <a href="<?php echo esc_attr( $post_source_url ); ?>" target="_blank">
  148.                     <span class="source-name"><?php echo esc_attr( $post_source_name ); ?></span>
  149.                 </a>
  150.             </div><!-- .post-source-wrapper -->
  151.         <?php
  152.         }
  153.     }
  154.     if( 'post' == get_post_type() && !is_tag() ) {
  155.         $trans_tagged = of_get_option( 'trans_tagged' );
  156.         $apmag_show_tags = of_get_option('show_tags_post');
  157.          if( $apmag_show_tags != '0' ) {
  158.             /* translators: used between list items, there is a space after the comma */
  159.             $tags_list = get_the_tag_list( '', __( ' ', 'accesspress-mag' ) );
  160.             if ( $tags_list ) {
  161.               if( empty( $trans_tagged ) ){
  162.                   printf( '<span class="tags-links">' . __( 'Tagged %1$s', 'accesspress-mag' ) . '</span>', $tags_list );
  163.               } else {
  164.                   printf( '<span class="tags-links">' .$trans_tagged.' %1$s </span>', $tags_list );
  165.               }
  166.             }
  167.         }
  168.     }
  169.     edit_post_link( __( 'Edit', 'accesspress-mag' ), '<span class="edit-link">', '</span>' );
  170. }
  171. endif;
  172.  
  173. if ( ! function_exists( 'apmag_the_archive_title' ) ) :
  174. /**
  175.  * Shim for `the_archive_title()`.
  176.  *
  177.  * Display the archive title based on the queried object.
  178.  *
  179.  * @todo Remove this function when WordPress 4.3 is released.
  180.  *
  181.  * @param string $before Optional. Content to prepend to the title. Default empty.
  182.  * @param string $after  Optional. Content to append to the title. Default empty.
  183.  */
  184. function apmag_the_archive_title( $before = '', $after = '' ) {
  185.     if ( is_category() ) {
  186.         $title = sprintf( __( '%s', 'accesspress-mag' ), single_cat_title( '', false ) );
  187.     } elseif ( is_tag() ) {
  188.         $title = sprintf( __( 'Tag: %s', 'accesspress-mag' ), single_tag_title( '', false ) );
  189.     } elseif ( is_author() ) {
  190.         $title = sprintf( __( 'Author: %s', 'accesspress-mag' ), '<span class="vcard">' . get_the_author() . '</span>' );
  191.     } elseif ( is_year() ) {
  192.         $title = sprintf( __( 'Year: %s', 'accesspress-mag' ), get_the_date( _x( 'Y', 'yearly archives date format', 'accesspress-mag' ) ) );
  193.     } elseif ( is_month() ) {
  194.         $title = sprintf( __( 'Month: %s', 'accesspress-mag' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'accesspress-mag' ) ) );
  195.     } elseif ( is_day() ) {
  196.         $title = sprintf( __( 'Day: %s', 'accesspress-mag' ), get_the_date( _x( 'F j, Y', 'daily archives date format', 'accesspress-mag' ) ) );
  197.     } elseif ( is_tax( 'post_format' ) ) {
  198.         if ( is_tax( 'post_format', 'post-format-aside' ) ) {
  199.             $title = _x( 'Asides', 'post format archive title', 'accesspress-mag' );
  200.         } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
  201.             $title = _x( 'Galleries', 'post format archive title', 'accesspress-mag' );
  202.         } elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
  203.             $title = _x( 'Images', 'post format archive title', 'accesspress-mag' );
  204.         } elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
  205.             $title = _x( 'Videos', 'post format archive title', 'accesspress-mag' );
  206.         } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
  207.             $title = _x( 'Quotes', 'post format archive title', 'accesspress-mag' );
  208.         } elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
  209.             $title = _x( 'Links', 'post format archive title', 'accesspress-mag' );
  210.         } elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
  211.             $title = _x( 'Statuses', 'post format archive title', 'accesspress-mag' );
  212.         } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
  213.             $title = _x( 'Audio', 'post format archive title', 'accesspress-mag' );
  214.         } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
  215.             $title = _x( 'Chats', 'post format archive title', 'accesspress-mag' );
  216.         }
  217.     } elseif ( is_post_type_archive() ) {
  218.         $title = sprintf( __( 'Archives: %s', 'accesspress-mag' ), post_type_archive_title( '', false ) );
  219.     } elseif ( is_tax() ) {
  220.         $tax = get_taxonomy( get_queried_object()->taxonomy );
  221.         /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
  222.         $title = sprintf( __( '%1$s: %2$s', 'accesspress-mag' ), $tax->labels->singular_name, single_term_title( '', false ) );
  223.     } else {
  224.         $title = __( 'Archives', 'accesspress-mag' );
  225.     }
  226.  
  227.     /**
  228.      * Filter the archive title.
  229.      *
  230.      * @param string $title Archive title to be displayed.
  231.      */
  232.     $title = apply_filters( 'get_the_archive_title', $title );
  233.  
  234.     if ( ! empty( $title ) ) {
  235.         echo $before . $title . $after;
  236.     }
  237. }
  238. endif;
  239.  
  240. if ( ! function_exists( 'the_archive_description' ) ) :
  241. /**
  242.  * Shim for `the_archive_description()`.
  243.  *
  244.  * Display category, tag, or term description.
  245.  *
  246.  * @todo Remove this function when WordPress 4.3 is released.
  247.  *
  248.  * @param string $before Optional. Content to prepend to the description. Default empty.
  249.  * @param string $after  Optional. Content to append to the description. Default empty.
  250.  */
  251. function the_archive_description( $before = '', $after = '' ) {
  252.     $description = apply_filters( 'get_the_archive_description', term_description() );
  253.  
  254.     if ( ! empty( $description ) ) {
  255.         /**
  256.          * Filter the archive description.
  257.          *
  258.          * @see term_description()
  259.          *
  260.          * @param string $description Archive description to be displayed.
  261.          */
  262.         echo $before . $description . $after;
  263.     }
  264. }
  265. endif;
  266.  
  267. /**
  268.  * Returns true if a blog has more than 1 category.
  269.  *
  270.  * @return bool
  271.  */
  272. function accesspress_mag_categorized_blog() {
  273.     if ( false === ( $all_the_cool_cats = get_transient( 'accesspress_mag_categories' ) ) ) {
  274.         // Create an array of all the categories that are attached to posts.
  275.         $all_the_cool_cats = get_categories( array(
  276.             'fields'     => 'ids',
  277.             'hide_empty' => 1,
  278.  
  279.             // We only need to know if there is more than one category.
  280.             'number'     => 2,
  281.         ) );
  282.  
  283.         // Count the number of categories that are attached to the posts.
  284.         $all_the_cool_cats = count( $all_the_cool_cats );
  285.  
  286.         set_transient( 'accesspress_mag_categories', $all_the_cool_cats );
  287.     }
  288.  
  289.     if ( $all_the_cool_cats > 1 ) {
  290.         // This blog has more than 1 category so accesspress_mag_categorized_blog should return true.
  291.         return true;
  292.     } else {
  293.         // This blog has only 1 category so accesspress_mag_categorized_blog should return false.
  294.         return false;
  295.     }
  296. }
  297.  
  298. /**
  299.  * Flush out the transients used in accesspress_mag_categorized_blog.
  300.  */
  301. function accesspress_mag_category_transient_flusher() {
  302.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  303.         return;
  304.     }
  305.     // Like, beat it. Dig?
  306.     delete_transient( 'accesspress_mag_categories' );
  307. }
  308. add_action( 'edit_category', 'accesspress_mag_category_transient_flusher' );
  309. add_action( 'save_post',     'accesspress_mag_category_transient_flusher' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement