Guest User

loop.php

a guest
Oct 3rd, 2017
244
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Functions used in the main loop
  3.  *
  4.  * @package Anima
  5.  */
  6.  
  7. /**
  8.  * Sets the post excerpt length to the number of words set in the theme settings
  9.  */
  10. function anima_excerpt_length_words( $length ) {
  11.     if ( is_admin() ) {
  12.         return $length;
  13.     }
  14.  
  15.     return absint( cryout_get_option( 'anima_excerptlength' ) );
  16. }
  17. add_filter( 'excerpt_length', 'anima_excerpt_length_words' );
  18.  
  19. /**
  20.  * Adds a pretty "Continue Reading" link to custom post excerpts.
  21.  */
  22. function anima_custom_excerpt_more() {
  23.     if ( ! is_attachment() ) {
  24.          echo wp_kses_post( anima_continue_reading_link() );
  25.     }
  26. }
  27. add_action( 'cryout_post_excerpt_hook', 'anima_custom_excerpt_more', 10 );
  28.  
  29. /**
  30.  * Returns a "Continue Reading" link for excerpts
  31.  */
  32. function anima_continue_reading_link() {
  33.     $anima_excerptcont = cryout_get_option( 'anima_excerptcont' );
  34.     return '<a class="continue-reading-link" href="'. esc_url( get_permalink() ) . '"><span>' . wp_kses_post( $anima_excerptcont ). '</span><i class="icon-continue-reading"></i></a>';
  35. }
  36. add_filter( 'the_content_more_link', 'anima_continue_reading_link' );
  37.  
  38. /**
  39.  * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and anima_continue_reading_link().
  40.  */
  41. function anima_auto_excerpt_more( $more ) {
  42.     if ( is_admin() ) {
  43.         return $more;
  44.     }
  45.  
  46.     return wp_kses_post( cryout_get_option( 'anima_excerptdots' ) );
  47. }
  48. add_filter( 'excerpt_more', 'anima_auto_excerpt_more' );
  49.  
  50. /**
  51.  * Adds a "Continue Reading" link to post excerpts created using the <!--more--> tag.
  52.  */
  53. function anima_more_link( $more_link, $more_link_text ) {
  54.     $anima_excerptcont = cryout_get_option( 'anima_excerptcont' );
  55.     $new_link_text = $anima_excerptcont;
  56.     if ( preg_match( "/custom=(.*)/", $more_link_text, $m ) ) {
  57.         $new_link_text = $m[1];
  58.     }
  59.     $more_link = str_replace( $more_link_text, $new_link_text, $more_link );
  60.     $more_link = str_replace( 'more-link', 'continue-reading-link', $more_link );
  61.     return $more_link;
  62. }
  63. add_filter( 'the_content_more_link', 'anima_more_link', 10, 2 );
  64.  
  65. /**
  66.  * Remove inline styles printed when the gallery shortcode is used.
  67.  * Galleries are styled by the theme in style.css.
  68.  */
  69. function anima_remove_gallery_css( $css ) {
  70.     return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  71. }
  72. add_filter( 'gallery_style', 'anima_remove_gallery_css' );
  73.  
  74. /**
  75.  * Posted in category
  76.  */
  77. if ( ! function_exists( 'anima_posted_category' ) ) :
  78. function anima_posted_category() {
  79.     if ( 'post' !== get_post_type() ) return;
  80.     $anima_meta_category = cryout_get_option( 'anima_meta_category' );
  81.  
  82.     if ( $anima_meta_category && get_the_category_list() ) {
  83.         echo '<span class="bl_categ"' . cryout_schema_microdata( 'category', 0 ) . '>
  84.                     <i class="icon-category icon-metas" title="' . esc_attr__( "Categories", "anima" ) . '"></i> '
  85.                      . get_the_category_list( ' <span class="sep">/</span> ' ) .
  86.                 '</span>';
  87.     }
  88. } // anima_posted_category()
  89. endif;
  90.  
  91. /**
  92.  * Posted by author
  93.  */
  94. if ( ! function_exists( 'anima_posted_author' )) :
  95. function anima_posted_author() {
  96.     if ( 'post' !== get_post_type() ) return;
  97.     $anima_meta_author = cryout_get_option( 'anima_meta_author' );
  98.  
  99.     if ( $anima_meta_author ) {
  100.         echo sprintf(
  101.             '<span class="author vcard"' . cryout_schema_microdata( 'author', 0 ) . '>
  102.                 <i class="icon-author icon-metas" title="' . esc_attr__( "Author", "anima" ) . '"></i>
  103.                 <a class="url fn n" rel="author" href="%1$s" title="%2$s"' . cryout_schema_microdata( 'author-url', 0 ) . '>
  104.                     <em' .  cryout_schema_microdata( 'author-name', 0 ) . '>%3$s</em>
  105.                 </a>
  106.             </span>',
  107.             esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
  108.             sprintf( esc_attr__( 'View all posts by %s', 'anima' ), get_the_author() ),
  109.             get_the_author()
  110.         );
  111.     }
  112. } // anima_posted_author
  113. endif;
  114.  
  115. /**
  116.  * Posted by author for single posts
  117.  */
  118. if ( ! function_exists( 'anima_posted_author_single' )) :
  119. function anima_posted_author_single() {
  120.     $anima_meta_author = cryout_get_option( 'anima_meta_author' );
  121.     $anima_meta_date = cryout_get_option( 'anima_meta_date' );
  122.     $anima_meta_date = (( $anima_meta_date && !is_attachment() )?'<em>' . __("on", "anima").'</em>':""); // Hide 'on' if meta date is hidden or if attachment page
  123.     global $post;
  124.     $author_id = $post->post_author;
  125.  
  126.     if ( $anima_meta_author ) {
  127.         echo sprintf(
  128.             '<span class="author vcard"' . cryout_schema_microdata( 'author', 0 ) . '>' .
  129.                 get_avatar( $author_id ) . '<em>'. __("Posted by ", "anima") . '</em>' .
  130.                 '<a class="url fn n" rel="author" href="%1$s" title="%2$s"' . cryout_schema_microdata( 'author-url', 0 ) . '>
  131.                     <em' .  cryout_schema_microdata( 'author-name', 0 ) . '>%3$s</em>
  132.                 </a> ' . $anima_meta_date .
  133.             '</span>',
  134.             esc_url( get_author_posts_url( get_the_author_meta( 'ID',   $author_id ) ) ),
  135.             sprintf( esc_attr__( 'View all posts by %s', 'anima' ), get_the_author_meta( 'display_name', $author_id) ),
  136.             get_the_author_meta( 'display_name', $author_id)
  137.         );
  138.     }
  139. } // anima_posted_author_single
  140. endif;
  141.  
  142. /**
  143.  * Posted date/time, tags
  144.  */
  145. if ( ! function_exists( 'anima_posted_date' ) ) :
  146. function anima_posted_date() {
  147.     if ( 'post' !== get_post_type() ) return;
  148.     $anima_meta_date = cryout_get_option( 'anima_meta_date' );
  149.     $anima_meta_time = cryout_get_option( 'anima_meta_time' );
  150.  
  151.     // Post date/time
  152.     if ( $anima_meta_date || $anima_meta_time ) {
  153.         $date = ''; $time = '';
  154.         if ( $anima_meta_date ) { $date = get_the_date(); }
  155.         if ( $anima_meta_time ) { $time = esc_attr( get_the_time() ); }
  156.         ?>
  157.  
  158.         <span class="onDate date" >
  159.                 <i class="icon-date icon-metas" title="<?php esc_attr_e( "Date", "anima" ) ?>"></i>
  160.                 <time class="published" datetime="<?php echo get_the_time( 'c' ) ?>" <?php cryout_schema_microdata( 'time' ) ?>>
  161.                     <?php echo $date . ( ( $anima_meta_date && $anima_meta_time ) ? ', ' : '' ) . $time ?>
  162.                 </time>
  163.                 <time class="updated" datetime="<?php echo get_the_modified_time( 'c' )  ?>" <?php cryout_schema_microdata( 'time-modified' ) ?>><?php echo get_the_modified_date();?></time>
  164.         </span>
  165.         <?php
  166.     }
  167.  
  168. }; // anima_posted_date()
  169. endif;
  170.  
  171. if ( ! function_exists( 'anima_posted_tags' ) ) :
  172. function anima_posted_tags() {
  173.     if ( 'post' !== get_post_type() ) return;
  174.     $anima_meta_tag  = cryout_get_option( 'anima_meta_tag' );
  175.     // Retrieves tag list of current post, separated by commas.
  176.     $tag_list = get_the_tag_list( '', ' / ' );
  177.     if ( $anima_meta_tag && $tag_list ) { ?>
  178.         <span class="tags" <?php cryout_schema_microdata( 'tags' ) ?>>
  179.                 <i class="icon-tag icon-metas" title="<?php esc_attr_e( 'Tagged', 'anima' ) ?>"></i>&nbsp;<?php echo $tag_list ?>
  180.         </span>
  181.         <?php
  182.     }
  183. }//anima_posted_tags()
  184. endif;
  185.  
  186. /**
  187.  * Post edit link for editors
  188.  */
  189. if ( ! function_exists( 'anima_posted_edit' ) ) :
  190. function anima_posted_edit() {
  191.     edit_post_link( __( 'Edit', 'anima' ), '<span class="edit-link icon-metas"><i class="icon-edit icon-metas"></i> ', '</span>' );
  192. }; // anima_posted_edit()
  193. endif;
  194.  
  195. /**
  196.  * Post format meta
  197.  */
  198. if ( ! function_exists( 'anima_meta_format' ) ) :
  199. function anima_meta_format() {
  200.     if ( 'post' !== get_post_type() ) return;
  201.     $format = get_post_format();
  202.     if ( is_sticky() ) echo '<span class="entry-sticky">' . __('Featured', 'anima') . '</span>';
  203.     if ( current_theme_supports( 'post-formats', $format ) ) {
  204.         printf( '<span class="entry-format"><a href="%1$s"><i class="icon-%2$s" title="%3$s"></i></a></span>',
  205.             esc_url( get_post_format_link( $format ) ),
  206.             $format,
  207.             get_post_format_string( $format )
  208.         );
  209.     }
  210. } //anima_meta_format()
  211. endif;
  212.  
  213. /**
  214.  * Post format info
  215.  */
  216. function anima_meta_infos() {
  217.  
  218.     add_action( 'cryout_featured_hook', 'anima_posted_edit', 50 ); // Edit button
  219.     add_action( 'cryout_post_excerpt_hook', 'anima_comments_on', 50 ); // Comments
  220.  
  221.     if ( is_single() ) { // If single, metas are shown after the title
  222.  
  223.         add_action( 'cryout_post_meta_hook',    'anima_posted_author_single', 10 );
  224.         add_action( 'cryout_post_meta_hook',    'anima_posted_date', 20 );
  225.         add_action( 'cryout_post_meta_hook',    'anima_posted_category', 30 );
  226.  
  227.     } else { // if blog page, metas are shown at the top of the article
  228.  
  229.         add_action( 'cryout_featured_meta_hook',    'anima_posted_author', 15 );
  230.         add_action( 'cryout_featured_meta_hook',    'anima_posted_date', 20 );
  231.         add_action( 'cryout_featured_meta_hook',    'anima_posted_category', 30 );
  232.  
  233.     }
  234.  
  235.     add_action( 'cryout_post_utility_hook', 'anima_posted_tags', 40 ); // Tags always at the bottom of the article
  236.     add_action( 'cryout_featured_meta_hook', 'anima_meta_format', 10 ); // Post format
  237. } //anima_meta_infos()
  238. add_action( 'wp_head', 'anima_meta_infos' );
  239.  
  240. /* Remove category from rel in category tags */
  241. function anima_remove_category_tag( $text ) {
  242.     $text = str_replace( 'rel="category tag"', 'rel="tag"', $text );
  243.     return $text;
  244. } //anima_remove_category_tag()
  245. //add_filter( 'the_category', 'anima_remove_category_tag' );
  246. //add_filter( 'get_the_category_list', 'anima_remove_category_tag' );
  247.  
  248. /**
  249.  * Backup navigation
  250.  */
  251. if ( ! function_exists( 'anima_content_nav' ) ) :
  252. function anima_content_nav( $nav_id ) {
  253.     global $wp_query;
  254.     if ( $wp_query->max_num_pages > 1 ) : ?>
  255.  
  256.         <nav id="<?php echo $nav_id; ?>" class="navigation">
  257.  
  258.             <span class="nav-previous">
  259.                  <?php next_posts_link( '<i class="icon-angle-left"></i>' . __( 'Older posts', 'anima' ) ); ?>
  260.             </span>
  261.  
  262.             <span class="nav-next">
  263.                 <?php previous_posts_link( __( 'Newer posts', 'anima' ) . '<i class="icon-angle-right"></i>' ); ?>
  264.             </span>
  265.  
  266.         </nav><!-- #<?php echo $nav_id; ?> -->
  267.  
  268.     <?php endif;
  269. }; // anima_content_nav()
  270. endif;
  271.  
  272. /**
  273.  * Adds a post thumbnail and if one doesn't exist the first post image is returned
  274.  * @uses cryout_get_first_image( $postID )
  275.  */
  276. if ( ! function_exists( 'anima_set_featured_thumb' ) ) :
  277. function anima_set_featured_thumb() {
  278.  
  279.     global $post;
  280.     $options = cryout_get_option( array( 'anima_fpost', 'anima_fauto', 'anima_falign', 'anima_magazinelayout', 'anima_landingpage' ) );
  281.  
  282.     switch ($options['anima_magazinelayout']) {
  283.         case 3: $featured = 'anima-featured-third'; break;
  284.         case 2: $featured = 'anima-featured-half'; break;
  285.         case 1: default: $featured = 'anima-featured'; break;
  286.     }
  287.  
  288.     // filter to disable srcset if so desired
  289.     $use_srcset = apply_filters( 'anima_featured_srcset', true );
  290.  
  291.     if ( function_exists('has_post_thumbnail') && has_post_thumbnail() && $options['anima_fpost']) {
  292.         // has featured image
  293.         $featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), $featured );
  294.     } elseif ( $options['anima_fpost'] && $options['anima_fauto'] && empty($featured_image) ) {
  295.         // get the first image from post
  296.         $featured_image = cryout_post_first_image( $post->ID, $featured );
  297.     } else {
  298.         // featured image not enabled or not obtainable
  299.         $featured_image[0] = apply_filters('anima_preview_img_src', '');
  300.         $featured_image[1] = apply_filters('anima_preview_img_w', '');
  301.         $featured_image[2] = apply_filters('anima_preview_img_h', '');
  302.     };
  303.  
  304.     if ( ! empty( $featured_image[0] ) ) {
  305.         $featured_image_url = esc_url( $featured_image[0] );
  306.         $featured_image_w = $featured_image[1];
  307.         $featured_image_h = $featured_image[2]; ?>
  308.         <div class="post-thumbnail-container"  <?php cryout_schema_microdata( 'image' ); ?>>
  309.  
  310.             <a href="<?php echo esc_url( get_permalink( $post->ID ) ) ?>" title="<?php echo esc_attr( get_post_field( 'post_title', $post->ID ) ) ?>"
  311.                 <?php cryout_echo_bgimage( $featured_image_url, 'post-featured-image' ) ?>>
  312.  
  313.             </a>
  314.             <a class="responsive-featured-image" href="<?php echo esc_url( get_permalink( $post->ID ) ) ?>" title="<?php echo esc_attr( get_post_field( 'post_title', $post->ID ) ) ?>">
  315.                 <img class="post-featured-image" alt="<?php the_title_attribute();?>" <?php cryout_schema_microdata( 'url' ); ?>
  316.                 src="<?php echo $featured_image_url; ?>" srcset="<?php if ($use_srcset) echo cryout_get_featured_srcset(
  317.                         get_post_thumbnail_id( $post->ID ),
  318.                         array(  'anima-featured',
  319.                                 'anima-featured-full',
  320.                                 'anima-featured-half',
  321.                                 'anima-featured-third' )
  322.                         ) ?>" sizes="<?php if ($use_srcset) echo cryout_gen_featured_sizes( anima_featured_width(), $options['anima_magazinelayout'], $options['anima_landingpage'] ) ?>"/>
  323.             </a>
  324.             <meta itemprop="width" content="<?php echo absint( $featured_image_w ); ?>">
  325.             <meta itemprop="height" content="<?php echo absint( $featured_image_h ); ?>">
  326.             <div class="entry-meta featured-image-meta"><?php cryout_featured_meta_hook(); ?></div>
  327.         </div>
  328.     <?php
  329.         } else { ?>
  330.         <div class="entry-meta featured-image-meta"><?php cryout_featured_meta_hook(); ?></div>
  331.         <?php }
  332. } // anima_set_featured_thumb()
  333. endif;
  334. if ( cryout_get_option( 'anima_fpost' ) ) add_action( 'cryout_featured_hook', 'anima_set_featured_thumb' );
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×