Advertisement
cipher87

loop-index.php

Oct 5th, 2020
1,447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.89 KB | None | 0 0
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  3.  
  4.  
  5. global $avia_config, $post_loop_count;
  6.  
  7.  
  8. if( empty( $post_loop_count ) )
  9. {
  10.     $post_loop_count = 1;
  11. }
  12.  
  13. $blog_style = ! empty( $avia_config['blog_style'] ) ? $avia_config['blog_style'] : avia_get_option( 'blog_style', 'multi-big' );
  14. if( is_single() )
  15. {
  16.     $blog_style = avia_get_option( 'single_post_style', 'single-big' );
  17. }
  18.  
  19. $blog_global_style = avia_get_option( 'blog_global_style','' ); //alt: elegant-blog
  20.  
  21. $blog_disabled = ( avia_get_option('disable_blog') == 'disable_blog' ) ? true : false;
  22. if( $blog_disabled )
  23. {
  24.     if( current_user_can( 'edit_posts' ) )
  25.     {
  26.         $msg  = '<strong>' . __( 'Admin notice for:', 'avia_framework' ) . '</strong><br>';
  27.         $msg .= __( 'Blog Posts', 'avia_framework' ) . '<br><br>';
  28.         $msg .= __( 'This element was disabled in your theme settings. You can activate it here:', 'avia_framework' ) . '<br>';
  29.         $msg .= '<a target="_blank" href="' . admin_url( 'admin.php?page=avia#goto_performance') . '">' . __( 'Performance Settings', 'avia_framework' ) . '</a>';
  30.        
  31.         $content    = "<span class='av-shortcode-disabled-notice'>{$msg}</span>";
  32.        
  33.         echo $content;
  34.     }
  35.    
  36.      return;
  37. }
  38.  
  39.  
  40.  
  41.  
  42. $initial_id = avia_get_the_ID();
  43.  
  44. // check if we got posts to display:
  45. if( have_posts() ) :
  46.  
  47.     while( have_posts() ) : the_post();
  48.  
  49.        
  50.     /*
  51.      * get the current post id, the current post class and current post format
  52.      */
  53.     $url = '';
  54.     $current_post = array();
  55.     $current_post['post_loop_count'] = $post_loop_count;
  56.     $current_post['the_id'] = get_the_ID();
  57.     $current_post['parity'] = $post_loop_count % 2 ? 'odd' : 'even';
  58.     $current_post['last'] = count( $wp_query->posts ) == $post_loop_count ? ' post-entry-last ' : '';
  59.     $current_post['post_type'] = get_post_type( $current_post['the_id'] );
  60.     $current_post['post_class'] = 'post-entry-' . $current_post['the_id'] . ' post-loop-' . $post_loop_count . ' post-parity-' . $current_post['parity'] . $current_post['last'] . ' ' . $blog_style;
  61.     $current_post['post_class'] .= ( $current_post['post_type'] == 'post' ) ? '' : ' post';
  62.     $current_post['post_format'] = get_post_format() ? get_post_format() : 'standard';
  63.     $current_post['post_layout'] = avia_layout_class('main', false);
  64.     $blog_content = ! empty( $avia_config['blog_content'] ) ? $avia_config['blog_content'] : 'content';
  65.    
  66.     /*If post uses builder change content to exerpt on overview pages*/
  67.     if( Avia_Builder()->get_alb_builder_status( $current_post['the_id'] ) && !is_singular($current_post['the_id']) && $current_post['post_type'] == 'post')
  68.     {
  69.        $current_post['post_format'] = 'standard';
  70.        $blog_content = 'excerpt_read_more';
  71.     }
  72.    
  73.     /**
  74.      * Allows especially for ALB posts to change output to 'content'
  75.      * Supported since 4.5.5
  76.      *
  77.      * @since 4.5.5
  78.      * @return string
  79.      */
  80.     $blog_content = apply_filters( 'avf_blog_content_in_loop', $blog_content, $current_post, $blog_style, $blog_global_style );
  81.    
  82.  
  83.     /*
  84.      * retrieve slider, title and content for this post,...
  85.      */
  86.     $size = strpos( $blog_style, 'big' ) ? ( ( strpos($current_post['post_layout'], 'sidebar') !== false ) ? 'entry_with_sidebar' : 'entry_without_sidebar' ) : 'square';
  87.    
  88.     if( ! empty( $avia_config['preview_mode'] ) && ! empty( $avia_config['image_size'] ) && $avia_config['preview_mode'] == 'custom' )
  89.     {
  90.         $size = $avia_config['image_size'];
  91.     }
  92.    
  93.     /**
  94.      * @since 4.5.4
  95.      * @return string
  96.      */
  97.     $current_post['slider'] = apply_filters( 'avf_post_featured_image_link', get_the_post_thumbnail( $current_post['the_id'], $size ), $current_post, $size );
  98.    
  99.     /**
  100.      * Backwards comp. to checkbox prior v4.5.3 (now selectbox with '' or '1')
  101.      */
  102.     $hide_featured_image = empty( get_post_meta( $current_post['the_id'], '_avia_hide_featured_image', true ) ) ? false : true;
  103.     if( is_single( $initial_id ) && $hide_featured_image )
  104.     {
  105.         $current_post['slider'] = '';
  106.     }
  107.    
  108.     $current_post['title'] = get_the_title();
  109.    
  110.     /**
  111.      * Allow 3rd party to hook and return a plugin specific content.
  112.      * This returned content replaces Enfold's standard content building procedure.
  113.      *
  114.      * @since 4.5.7.2
  115.      * @param string
  116.      * @param string $context
  117.      * @return string
  118.      */
  119.     $current_post['content'] = apply_filters( 'avf_the_content', '', 'loop_index' );
  120.     if( '' == $current_post['content'] )
  121.     {
  122.         $current_post['content']    = $blog_content == 'content' ? get_the_content(__('Read more','avia_framework').'<span class="more-link-arrow"></span>') : get_the_excerpt();
  123.         $current_post['content']    = $blog_content == 'excerpt_read_more' ? $current_post['content'].'<div class="read-more-link"><a href="' . get_permalink() . '" class="more-link">' . __( 'Read more', 'avia_framework' ) . '<span class="more-link-arrow"></span></a></div>' : $current_post['content'];
  124.         $current_post['before_content'] = '';
  125.  
  126.         /*
  127.          * ...now apply a filter, based on the post type... (filter function is located in includes/helper-post-format.php)
  128.          */
  129.         $current_post   = apply_filters( 'post-format-'.$current_post['post_format'], $current_post );
  130.         $with_slider    = empty( $current_post['slider'] ) ? '' : 'with-slider';
  131.        
  132.         /*
  133.          * ... last apply the default wordpress filters to the content
  134.          */
  135.         $current_post['content'] = str_replace( ']]>', ']]&gt;', apply_filters( 'the_content', $current_post['content'] ) );
  136.     }
  137.  
  138.     /*
  139.      * Now extract the variables so that $current_post['slider'] becomes $slider, $current_post['title'] becomes $title, etc
  140.      */
  141.     extract( $current_post );
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.     /*
  151.      * render the html:
  152.      */
  153.  
  154.     echo "<article class='" . implode( ' ', get_post_class( 'post-entry post-entry-type-'.$post_format . ' ' . $post_class . ' ' . $with_slider)) . "' " . avia_markup_helper( array( 'context' => 'entry', 'echo' => false ) ) . '>';
  155.        
  156.        
  157.        
  158.         //default link for preview images
  159.         $link = ! empty( $url ) ? $url : get_permalink();
  160.        
  161.         //preview image description
  162.         $desc = '';
  163.         $thumb_post = get_post( get_post_thumbnail_id() );
  164.         if( $thumb_post instanceof WP_Post )
  165.         {
  166.             if( '' != trim( $thumb_post->post_excerpt ) )
  167.             {
  168.                 //  return 'Caption' from media gallery
  169.                 $desc = $thumb_post->post_excerpt;
  170.             }
  171.             else if( '' != trim( $thumb_post->post_title ) )
  172.             {
  173.                 //  return 'Title' from media gallery
  174.                 $desc = $thumb_post->post_title;
  175.             }
  176.             else if( '' != trim( $thumb_post->post_content ) )
  177.             {
  178.                 //  return 'Description' from media gallery
  179.                 $desc = $thumb_post->post_content;
  180.             }
  181.         }
  182.        
  183.         $desc = trim( $desc );
  184.         if( '' == $desc )
  185.         {
  186.             $desc = trim( the_title_attribute( 'echo=0' ) );
  187.         }
  188.        
  189.         /**
  190.          * Allows to change the title attribute text for the featured image.
  191.          * If '' is returned, then no title attribute is added.
  192.          *
  193.          * @since 4.6.4
  194.          * @param string $desc
  195.          * @param string $context               'loop_index'
  196.          * @param WP_Post $thumb_post
  197.          */
  198.         $featured_img_title = apply_filters( 'avf_featured_image_title_attr', $desc, 'loop_index', $thumb_post );
  199.        
  200.         $featured_img_title = '' != trim( $featured_img_title ) ? ' title="' . esc_attr( $featured_img_title ) . '" ' : '';
  201.  
  202.         //on single page replace the link with a fullscreen image
  203.         if( is_singular() )
  204.         {
  205.             $link = avia_image_by_id( get_post_thumbnail_id(), 'large', 'url' );
  206.         }
  207.  
  208.         if( ! in_array( $blog_style, array( 'bloglist-simple', 'bloglist-compact', 'bloglist-excerpt' ) ) )
  209.         {
  210.             //echo preview image
  211.             if( strpos( $blog_global_style, 'elegant-blog' ) === false )
  212.             {
  213.                 if( strpos( $blog_style, 'big' ) !== false )
  214.                 {
  215.                     if( $slider )
  216.                     {
  217.                         $slider = '<a href="' . $link . '" ' . $featured_img_title . '>' . $slider . '</a>';
  218.                     }
  219.                    
  220.                     if( $slider )
  221.                     {
  222.                         echo '<div class="big-preview ' . $blog_style . '" ' . avia_markup_helper( array( 'context' => 'image', 'echo' => false ) ) . '>' . $slider . '</div>';
  223.                     }
  224.                 }
  225.  
  226.                 if( ! empty( $before_content ) )
  227.                 {
  228.                     echo '<div class="big-preview ' . $blog_style . '">' . $before_content . '</div>';
  229.                 }
  230.             }
  231.         }
  232.        
  233.         echo "<div class='blog-meta'>";
  234.  
  235.             $blog_meta_output = '';
  236.             $icon = '<span class="iconfont" ' . av_icon_string( $post_format ) . '></span>';
  237.  
  238.             if( strpos( $blog_style, 'multi' ) !== false )
  239.             {
  240.                 $gravatar = '';
  241.                 $pf_link = get_post_format_link( $post_format );
  242.  
  243.                 if( $post_format == 'standard' )
  244.                 {
  245.                     $author_name = apply_filters( 'avf_author_name', get_the_author_meta( 'display_name', $post->post_author ), $post->post_author );
  246.                     $author_email = apply_filters( 'avf_author_email', get_the_author_meta('email', $post->post_author), $post->post_author );
  247.  
  248.                     $gravatar_alt = esc_html( $author_name );
  249.                     $gravatar = get_avatar( $author_email, '81', 'blank', $gravatar_alt );
  250.                     $pf_link = get_author_posts_url( $post->post_author );
  251.                 }
  252.  
  253.                 $blog_meta_output = "<a href='{$pf_link}' class='post-author-format-type'><span class='rounded-container'>" . $gravatar . $icon . '</span></a>';
  254.             }
  255.             else if( strpos( $blog_style, 'small' ) !== false )
  256.             {
  257.                 $blog_meta_output = "<a href='{$link}' class='small-preview' {$featured_img_title} " . avia_markup_helper( array( 'context' => 'image', 'echo' => false ) ). ">" . $slider . $icon . '</a>';
  258.             }
  259.  
  260.             echo apply_filters( 'avf_loop_index_blog_meta', $blog_meta_output );
  261.  
  262.         echo '</div>';
  263.  
  264.         echo "<div class='entry-content-wrapper clearfix {$post_format}-content'>";
  265.             echo '<header class="entry-content-header">';
  266.  
  267.                 if( $blog_style == 'bloglist-compact' )
  268.                 {
  269.                     $format = get_post_format();
  270.                     echo "<span class=' fallback-post-type-icon' " . av_icon_string($format) . '></span>';
  271.                 }
  272.  
  273.                 $close_header   = '</header>';
  274.                
  275.                 $content_output  = '<div class="entry-content" ' . avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false ) ) . '>';
  276.                 $content_output .=      $content;
  277.                 $content_output .= '</div>';
  278.                
  279.                
  280.                 $taxonomies  = get_object_taxonomies( get_post_type( $the_id ) );
  281.                 $cats = '';
  282.                 $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array('post_tag','post_format') );
  283.                 $excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $the_id ), $the_id );
  284.  
  285.                 if( ! empty( $taxonomies ) )
  286.                 {
  287.                     foreach( $taxonomies as $taxonomy )
  288.                     {
  289.                         if( ! in_array( $taxonomy, $excluded_taxonomies ) )
  290.                         {
  291.                             $cats .= get_the_term_list( $the_id, $taxonomy, '', ', ', '' ) . ' ';
  292.                         }
  293.                     }
  294.                 }
  295.                
  296.                 $sb_meta = '';
  297.                 if( $blog_style === 'single-big' )
  298.                 {
  299.                     $sb_meta .= "<span class='post-meta-infos'>";
  300.  
  301.                     $sb_meta .=  "<time class='date-container minor-meta updated' >" . get_the_time( get_option( 'date_format' ) ) . '</time>';
  302.                     $sb_meta .=  "<span class='text-sep text-sep-date'>/</span>";
  303.  
  304.                     if ( get_comments_number() != '0' || comments_open() )
  305.                     {
  306.                         $sb_meta .=  "<span class='comment-container minor-meta'>";
  307.                         ob_start();
  308.                         comments_popup_link(  '0 ' . __( 'Comments', 'avia_framework' ),
  309.                                               '1 ' . __( 'Comment', 'avia_framework' ),
  310.                                               '% ' . __( 'Comments', 'avia_framework' ),
  311.                                               'comments-link',
  312.                                               '' . __( 'Comments Disabled','avia_framework' )
  313.                                 );
  314.                         $sb_meta .= ob_get_clean();
  315.                         $sb_meta .=  '</span>';
  316.                         $sb_meta .=  "<span class='text-sep text-sep-comment'>/</span>";
  317.                     }
  318.  
  319.                     $sb_meta .= '<span class="blog-author minor-meta">' . __( 'by','avia_framework' ) . ' ';
  320.                     $sb_meta .= '<span class="entry-author-link" ' . avia_markup_helper( array( 'context' => 'author_name', 'echo' => false ) ) . '>';
  321.                     $sb_meta .= '<span class="author"><span class="fn">';
  322.                     ob_start();
  323.                         the_author_posts_link();
  324.                     $sb_meta .= ob_get_clean();
  325.                     $sb_meta .= '</span></span>';
  326.                     $sb_meta .= '</span>';
  327.                     $sb_meta .= '</span>';
  328.  
  329.  
  330.                     $sb_meta .= '</span>';
  331.  
  332.                 }
  333.                
  334.                 //elegant blog
  335.                 //prev: if( $blog_global_style == 'elegant-blog' )
  336.                 if( strpos( $blog_global_style, 'elegant-blog' ) !== false )
  337.                 {
  338.                     $cat_output = '';
  339.  
  340.                     if( ! empty( $cats ) )
  341.                     {
  342.                         $cat_output .= '<span class="blog-categories minor-meta">';
  343.                         $cat_output .= $cats;
  344.                         $cat_output .= '</span>';
  345.                         $cats = '';
  346.                     }
  347.  
  348.                     if ( in_array( $blog_style, array( 'bloglist-compact', 'bloglist-excerpt' ) ) )
  349.                     {
  350.                         echo $title;
  351.                     }
  352.                     else
  353.                     {
  354.  
  355.                         // The wrapper div prevents the Safari reader from displaying the content twice  Β―\_(ツ)_/Β―
  356.                         echo '<div class="av-heading-wrapper">';
  357.  
  358.                         if( strpos( $blog_global_style, 'modern-blog' ) === false )
  359.                         {
  360.                             echo $cat_output . $title . $sb_meta;
  361.                         }
  362.                         else
  363.                         {
  364.                             echo $title . $cat_output . $sb_meta;
  365.                         }
  366.  
  367.                         echo '</div>';
  368.                     }
  369.  
  370.                     echo $close_header;
  371.                     $close_header = '';
  372.  
  373.                     if( ! in_array( $blog_style, array( 'bloglist-simple', 'bloglist-compact', 'bloglist-excerpt' ) ) )
  374.                     {
  375.  
  376.                         echo '<span class="av-vertical-delimiter"></span>';
  377.  
  378.                         //echo preview image
  379.                         if( strpos( $blog_style, 'big' ) !== false )
  380.                         {
  381.                             if( $slider )
  382.                             {
  383.                                 $slider = '<a href="' . $link . '" ' . $featured_img_title . '>' . $slider . '</a>';
  384.                             }
  385.  
  386.                             if( $slider )
  387.                             {
  388.                                 echo '<div class="big-preview ' . $blog_style . '" ' . avia_markup_helper( array( 'context' => 'image', 'echo' => false ) ) . '>' . $slider . '</div>';
  389.                             }
  390.                         }
  391.  
  392.  
  393.                         if( ! empty( $before_content ) )
  394.                         {
  395.                             echo '<div class="big-preview ' . $blog_style . '">' . $before_content . '</div>';
  396.                         }
  397.  
  398.                         echo $content_output;
  399.                     }
  400.                    
  401.                     $cats = '';
  402.                     $title = '';
  403.                     $content_output = '';
  404.                 }
  405.                
  406.                
  407.                 echo $title;
  408.  
  409.                 if( $blog_style !== 'bloglist-compact' )
  410.                 {
  411.                     if( $blog_style !== 'single-big' ) {
  412.                         echo "<span class='post-meta-infos'>";
  413.  
  414.                         echo "<time class='date-container minor-meta updated' >" . get_the_time( get_option( 'date_format' ) ) . '</time>';
  415.                         echo "<span class='text-sep text-sep-date'>/</span>";
  416.  
  417.                         if ( get_comments_number() != '0' || comments_open() )
  418.                         {
  419.  
  420.                             echo "<span class='comment-container minor-meta'>";
  421.                             comments_popup_link(  '0 ' . __( 'Comments', 'avia_framework' ),
  422.                                                 '1 ' . __( 'Comment', 'avia_framework' ),
  423.                                                 '% ' . __( 'Comments', 'avia_framework' ),
  424.                                                 'comments-link',
  425.                                                 '' . __( 'Comments Disabled','avia_framework' )
  426.                                     );
  427.                             echo '</span>';
  428.                             echo "<span class='text-sep text-sep-comment'>/</span>";
  429.                         }
  430.  
  431.  
  432.                         if( ! empty( $cats ) )
  433.                         {
  434.                             echo '<span class="blog-categories minor-meta">' . __( 'in','avia_framework' ) . ' ';
  435.                             echo    $cats;
  436.                             echo '</span><span class="text-sep text-sep-cat">/</span>';
  437.                         }
  438.  
  439.  
  440.                         echo '<span class="blog-author minor-meta">' . __( 'by','avia_framework' ) . ' ';
  441.                         echo    '<span class="entry-author-link" ' . avia_markup_helper( array( 'context' => 'author_name', 'echo' => false ) ) . '>';
  442.                         echo        '<span class="author"><span class="fn">';
  443.                                         the_author_posts_link();
  444.                         echo        '</span></span>';
  445.                         echo    '</span>';
  446.                         echo '</span>';
  447.                     }
  448.  
  449.                     if( $blog_style == 'bloglist-simple' )
  450.                     {
  451.                         echo '<div class="read-more-link"><a href="' . get_permalink() . '" class="more-link">' . __( 'Read more', 'avia_framework' ) . '<span class="more-link-arrow"></span></a></div>';
  452.                     }
  453.  
  454.                     echo '</span>';
  455.  
  456.                 } // display meta-infos on all layouts except bloglist-compact
  457.  
  458.             echo $close_header;
  459.  
  460.  
  461.             // echo the post content
  462.             if ( $blog_style == 'bloglist-excerpt')
  463.             {
  464.                 the_excerpt();
  465.                 echo '<div class="read-more-link"><a href="' . get_permalink() . '" class="more-link">' . __( 'Read more', 'avia_framework' ) . '<span class="more-link-arrow"></span></a></div>';
  466.             }
  467.  
  468.             if ( ! in_array( $blog_style, array( 'bloglist-simple', 'bloglist-compact', 'bloglist-excerpt' ) ) )
  469.             {
  470.                 echo $content_output;
  471.             }
  472.  
  473.  
  474.             echo '<footer class="entry-footer">';
  475.  
  476.             $avia_wp_link_pages_args = apply_filters( 'avf_wp_link_pages_args', array(
  477.                                                                         'before'    => '<nav class="pagination_split_post">' . __( 'Pages:', 'avia_framework' ),
  478.                                                                         'after'     => '</nav>',
  479.                                                                         'pagelink'  => '<span>%</span>',
  480.                                                                         'separator' => ' ',
  481.                                                                     ) );
  482.  
  483.             wp_link_pages( $avia_wp_link_pages_args );
  484.  
  485.             if( is_single() && ! post_password_required() )
  486.             {
  487.                 //tags on single post
  488.                 if(has_tag())
  489.                 {
  490.                     echo '<span class="blog-tags minor-meta">';
  491.                         the_tags( '<strong>' . __( 'Tags:', 'avia_framework' ) . '</strong><span> ' );
  492.                     echo '</span></span>';
  493.                 }
  494.                
  495.                 //share links on single post
  496.                 avia_social_share_links();
  497.    
  498.             }
  499.            
  500.             do_action( 'ava_after_content', $the_id, 'post' );
  501.  
  502.             echo '</footer>';
  503.  
  504.             echo "<div class='post_delimiter'></div>";
  505.         echo '</div>';
  506.         echo "<div class='post_author_timeline'></div>";
  507.         echo av_blog_entry_markup_helper( $current_post['the_id'] );
  508.        
  509.     echo '</article>';
  510.  
  511.     $post_loop_count++;
  512.     endwhile;
  513.     else:
  514.  
  515.             $default_heading = 'h1';
  516.             $args = array(
  517.                         'heading'       => $default_heading,
  518.                         'extra_class'   => ''
  519.                     );
  520.            
  521.             /**
  522.              * @since 4.5.5
  523.              * @return array
  524.              */
  525.             $args = apply_filters( 'avf_customize_heading_settings', $args, 'loop_index::nothing_found', array() );
  526.            
  527.             $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  528.             $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  529. ?>
  530.  
  531.     <article class="entry">
  532.         <header class="entry-content-header">
  533.             <?php echo "<{$heading} class='post-title entry-title {$css}'>" . __( 'Nothing Found', 'avia_framework' ) . "</{$heading}>"; ?>
  534.         </header>
  535.  
  536.         <p class="entry-content" <?php avia_markup_helper( array( 'context' => 'entry_content' ) ); ?>><?php _e( 'Sorry, no posts matched your criteria', 'avia_framework' ); ?></p>
  537.  
  538.         <footer class="entry-footer"></footer>
  539.     </article>
  540.  
  541. <?php
  542.  
  543.     endif;
  544.  
  545.     if( empty( $avia_config['remove_pagination'] ) )
  546.     {
  547.         echo "<div class='{$blog_style}'>" . avia_pagination( '', 'nav' ) . '</div>';
  548.     }
  549.  
  550.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement