Guenni007

loop-author

Nov 21st, 2025 (edited)
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.61 KB | None | 0 0
  1. <?php
  2. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  3.  
  4. /**
  5.  * Custom loop-author.php for Child-Theme (Enfold 7.1.3 compatible)
  6.  * Uses Grid or List Layout
  7.  * Place this file in: /wp-content/themes/enfold-child/includes/loop-author.php
  8.  * CSS file: /wp-content/themes/enfold-child/includes/loop-author.css
  9.  */
  10.  
  11. // Load CSS only once
  12. if( ! wp_style_is( 'enfold-child-loop-author', 'enqueued' ) ) {
  13.     $css_file = get_stylesheet_directory_uri() . '/includes/loop-author.css';
  14.     $css_path = get_stylesheet_directory() . '/includes/loop-author.css';
  15.    
  16.     // Only load if file exists
  17.     if( file_exists( $css_path ) ) {
  18.         wp_enqueue_style( 'enfold-child-loop-author', $css_file, array(), filemtime( $css_path ) );
  19.     }
  20. }
  21.  
  22. global $avia_config, $post_loop_count;
  23.  
  24. if( empty( $post_loop_count ) ) {
  25.     $post_loop_count = 1;
  26. }
  27.  
  28. // Default arguments for Author Loop
  29. $default_args = array(
  30.     'type'              => 'grid',
  31.     'columns'           => 4,
  32.     'items'             => get_option('posts_per_page', 12), // WordPress setting, fallback: 12
  33.     'contents'          => 'excerpt_read_more',
  34.     'preview_mode'      => 'auto',
  35.     'image_size'        => 'portfolio',
  36.     'paginate'          => 'yes',
  37.     'class'             => '',
  38.     'show_modified_date' => 'no',  // 'yes' or 'no' - shows "Updated: XX" if post was modified
  39.     'orderby'           => 'date',  // 'date', 'modified', 'title', 'rand', 'comment_count', 'menu_order'
  40.     'order'             => 'DESC',  // 'DESC' (newest first) or 'ASC' (oldest first)
  41.     'fallback_image'    => 'placeholder',      // URL to fallback image or 'placeholder' for grey area with icon
  42.     'post_types'        => array('post'), // Array: array('post'), array('portfolio'), or array('post', 'portfolio')
  43. );
  44.  
  45. /**
  46.  * Filter for Author Loop arguments
  47.  *
  48.  * @param array $default_args   Default arguments
  49.  * @param string $context       Always 'author' for this loop
  50.  * @return array                Filtered arguments
  51.  */
  52. $atts = apply_filters( 'avf_author_loop_args', $default_args, 'author' );
  53.  
  54. // Check if we got posts to display (uses the WordPress main query):
  55. if( have_posts() )
  56. {
  57.     // Container start - different classes for Grid vs. List
  58.     $container_class = 'av-author-loop-container';
  59.    
  60.     if( $atts['type'] == 'grid' ) {
  61.         $container_class .= ' av-author-grid-container av-author-grid';
  62.         // Add column class (only for grid)
  63.         $container_class .= ' av-columns-' . $atts['columns'];
  64.     } else {
  65.         $container_class .= ' av-author-list-container av-author-list';
  66.     }
  67.    
  68.     // Add custom class from filter
  69.     if( ! empty( $atts['class'] ) ) {
  70.         $container_class .= ' ' . esc_attr( $atts['class'] );
  71.     }
  72.    
  73.     /**
  74.      * Filter for additional CSS classes
  75.      */
  76.     $container_class = apply_filters( 'avf_author_loop_classes', $container_class, 'author', $atts );
  77.    
  78.     echo '<div class="' . esc_attr( $container_class ) . '">';
  79.    
  80.     while( have_posts() )
  81.     {
  82.         the_post();
  83.        
  84.         $post_id = get_the_ID();
  85.         $image_size = $atts['image_size'];
  86.         $post_format = get_post_format() ? get_post_format() : 'standard';
  87.        
  88.         // Get image or use fallback
  89.         $thumbnail = get_the_post_thumbnail( $post_id, $image_size );
  90.        
  91.         // If no thumbnail and fallback is defined
  92.         if( empty( $thumbnail ) && ! empty( $atts['fallback_image'] ) ) {
  93.             if( $atts['fallback_image'] == 'placeholder' ) {
  94.                 // Grey area with icon
  95.                 $thumbnail = '<div class="av-author-placeholder-image">';
  96.                 $thumbnail .= '<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">';
  97.                 $thumbnail .= '<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>';
  98.                 $thumbnail .= '<circle cx="8.5" cy="8.5" r="1.5"></circle>';
  99.                 $thumbnail .= '<polyline points="21 15 16 10 5 21"></polyline>';
  100.                 $thumbnail .= '</svg>';
  101.                 $thumbnail .= '</div>';
  102.             } else {
  103.                 // Custom fallback image URL
  104.                 $thumbnail = '<img src="' . esc_url( $atts['fallback_image'] ) . '" alt="' . esc_attr( get_the_title() ) . '" />';
  105.             }
  106.         }
  107.        
  108.         // Content based on setting
  109.         $show_content = '';
  110.         $show_title = true;
  111.         $show_read_more = false;
  112.        
  113.         // Determine what to show based on contents setting
  114.         switch( $atts['contents'] ) {
  115.             case 'title':
  116.                 // Only title (default: show_title already true)
  117.                 break;
  118.                
  119.             case 'title_read_more':
  120.                 // Title and read more
  121.                 $show_read_more = true;
  122.                 break;
  123.                
  124.             case 'only_excerpt':
  125.                 // Only excerpt, no title
  126.                 $show_title = false;
  127.                 $show_content = get_the_excerpt();
  128.                 break;
  129.                
  130.             case 'only_excerpt_read_more':
  131.                 // Excerpt and read more, no title
  132.                 $show_title = false;
  133.                 $show_content = get_the_excerpt();
  134.                 $show_read_more = true;
  135.                 break;
  136.                
  137.             case 'excerpt':
  138.                 // Title and excerpt (default)
  139.                 $show_content = get_the_excerpt();
  140.                 break;
  141.                
  142.             case 'excerpt_read_more':
  143.                 // Title, excerpt and read more
  144.                 $show_content = get_the_excerpt();
  145.                 $show_read_more = true;
  146.                 break;
  147.                
  148.             default:
  149.                 // Fallback to excerpt
  150.                 $show_content = get_the_excerpt();
  151.                 break;
  152.         }
  153.        
  154.         // Gather meta info
  155.         $meta_info = array();
  156.         $meta_separator = '<span class="text-sep">/</span>';
  157.        
  158.         // Published Date (from Enfold settings)
  159.         if( 'blog-meta-date' == avia_get_option( 'blog-meta-date' ) ) {
  160.             $meta_info['date'] = '<time class="date-container minor-meta updated" datetime="' . get_the_time('c', $post_id) . '">' . get_the_time( get_option('date_format'), $post_id ) . '</time>';
  161.         }
  162.        
  163.         // Modified Date (optional, controlled via filter)
  164.         if( $atts['show_modified_date'] == 'yes' ) {
  165.             $published_date = get_the_date( get_option('date_format'), $post_id );
  166.             $modified_date = get_the_modified_date( get_option('date_format'), $post_id );
  167.            
  168.             // Only show if actually modified
  169.             if( $published_date != $modified_date ) {
  170.                 $meta_info['modified'] = '<time class="date-container minor-meta modified-date" datetime="' . get_the_modified_time('c', $post_id) . '">' . __('Updated:', 'avia_framework') . ' ' . $modified_date . '</time>';
  171.             }
  172.         }
  173.        
  174.         if( 'blog-meta-comments' == avia_get_option( 'blog-meta-comments' ) ) {
  175.             if( get_comments_number() != '0' && comments_open() ) {
  176.                 ob_start();
  177.                 comments_popup_link(
  178.                     "0 " . __( 'Comments', 'avia_framework' ),
  179.                     "1 " . __( 'Comment' , 'avia_framework' ),
  180.                     "% " . __( 'Comments', 'avia_framework' ),
  181.                     'comments-link',
  182.                     __( 'Comments Disabled', 'avia_framework' )
  183.                 );
  184.                 $meta_info['comments'] = '<span class="comment-container minor-meta">' . ob_get_clean() . '</span>';
  185.             }
  186.         }
  187.        
  188.         $taxonomies = get_object_taxonomies( get_post_type( $post_id ) );
  189.         $cats = '';
  190.         $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array( 'post_tag', 'post_format' ) );
  191.         $excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $post_id ), $post_id, 'loop-author' );
  192.        
  193.         if( ! empty( $taxonomies ) ) {
  194.             foreach( $taxonomies as $taxonomy ) {
  195.                 if( ! in_array( $taxonomy, $excluded_taxonomies ) ) {
  196.                     $cats .= get_the_term_list( $post_id, $taxonomy, '', ', ','' ) . ' ';
  197.                 }
  198.             }
  199.         }
  200.        
  201.         if( 'blog-meta-category' == avia_get_option( 'blog-meta-category' ) && ! empty( $cats ) ) {
  202.             $meta_info['categories'] = '<span class="blog-categories minor-meta">' . __( 'in', 'avia_framework') . ' ' . trim( $cats ) . '</span>';
  203.         }
  204.        
  205.         $meta_info = apply_filters( 'avf_post_metadata_array', $meta_info, 'loop-author' );
  206.        
  207.         // Parity for columns (only relevant for grid)
  208.         $parity = '';
  209.         $first = $post_loop_count == 1 ? 'first' : '';
  210.        
  211.         // Grid Layout
  212.         if( $atts['type'] == 'grid' ) {
  213.         ?>
  214.         <article class="flex_column post-entry post-entry-<?php echo $post_id; ?> <?php echo $first; ?> <?php echo $parity; ?> post-entry-type-<?php echo $post_format; ?>">
  215.            
  216.             <div class="av-author-grid-item">
  217.                
  218.                 <?php if( $thumbnail ): ?>
  219.                 <a href="<?php the_permalink(); ?>" class="av-author-grid-image-link" title="<?php echo esc_attr( get_the_title() ); ?>">
  220.                     <div class="av-author-grid-image">
  221.                         <?php echo $thumbnail; ?>
  222.                         <?php if( has_post_thumbnail( $post_id ) ): ?>
  223.                         <div class="av-author-grid-overlay"></div>
  224.                         <?php endif; ?>
  225.                     </div>
  226.                 </a>
  227.                 <?php endif; ?>
  228.                
  229.                 <div class="av-author-grid-content">
  230.                     <header class="entry-content-header">
  231.                         <?php if( $show_title ): ?>
  232.                         <h3 class="av-author-grid-title entry-title">
  233.                             <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  234.                         </h3>
  235.                         <?php endif; ?>
  236.                        
  237.                         <?php if( ! empty( $meta_info ) ): ?>
  238.                         <span class="av-author-grid-meta">
  239.                             <?php echo implode( $meta_separator, $meta_info ); ?>
  240.                         </span>
  241.                         <?php endif; ?>
  242.                     </header>
  243.                    
  244.                     <?php if( ! empty( $show_content ) ): ?>
  245.                     <div class="av-author-grid-excerpt entry-content">
  246.                         <?php echo wpautop( $show_content ); ?>
  247.                     </div>
  248.                     <?php endif; ?>
  249.                 </div>
  250.                
  251.                 <?php if( $show_read_more ): ?>
  252.                 <div class="av-author-grid-read-more">
  253.                     <a href="<?php the_permalink(); ?>" class="more-link"><?php _e('Read more', 'avia_framework'); ?><span class="more-link-arrow">→</span></a>
  254.                 </div>
  255.                 <?php endif; ?>
  256.                
  257.             </div>
  258.            
  259.         </article>
  260.         <?php
  261.         }
  262.         // List Layout
  263.         else {
  264.         ?>
  265.         <article class="av-author-list-item post-entry post-entry-<?php echo $post_id; ?> <?php echo $first; ?> post-entry-type-<?php echo $post_format; ?>">
  266.            
  267.             <?php if( $thumbnail ): ?>
  268.             <div class="av-author-list-image">
  269.                 <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( get_the_title() ); ?>">
  270.                     <?php echo $thumbnail; ?>
  271.                 </a>
  272.             </div>
  273.             <?php endif; ?>
  274.            
  275.             <div class="av-author-list-content">
  276.                 <header class="entry-content-header">
  277.                     <?php if( $show_title ): ?>
  278.                     <h3 class="av-author-list-title entry-title">
  279.                         <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  280.                     </h3>
  281.                     <?php endif; ?>
  282.                    
  283.                     <?php if( ! empty( $meta_info ) ): ?>
  284.                     <span class="av-author-list-meta">
  285.                         <?php echo implode( $meta_separator, $meta_info ); ?>
  286.                     </span>
  287.                     <?php endif; ?>
  288.                 </header>
  289.                
  290.                 <?php if( ! empty( $show_content ) ): ?>
  291.                 <div class="av-author-list-excerpt entry-content">
  292.                     <?php echo wpautop( $show_content ); ?>
  293.                 </div>
  294.                 <?php endif; ?>
  295.                
  296.                 <?php if( $show_read_more ): ?>
  297.                 <div class="av-author-list-read-more">
  298.                     <a href="<?php the_permalink(); ?>" class="more-link"><?php _e('Read more', 'avia_framework'); ?><span class="more-link-arrow">→</span></a>
  299.                 </div>
  300.                 <?php endif; ?>
  301.             </div>
  302.            
  303.         </article>
  304.         <?php
  305.         }
  306.        
  307.         $post_loop_count++;
  308.     }
  309.    
  310.     echo '</div>'; // End container
  311.    
  312.     // Pagination
  313.     if( ! isset( $avia_config['remove_pagination'] ) && $atts['paginate'] == 'yes' ) {
  314.         echo '<div class="av-author-pagination">';
  315.         echo avia_pagination( '', 'nav' );
  316.         echo '</div>';
  317.     }
  318. }
  319. else
  320. {
  321.     // Nothing found
  322.     $default_heading = 'h1';
  323.     $args = array(
  324.         'heading'       => $default_heading,
  325.         'extra_class'   => ''
  326.     );
  327.    
  328.     $args = apply_filters( 'avf_customize_heading_settings', $args, 'loop_author::nothing_found', array() );
  329.    
  330.     $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  331.     $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  332.    
  333.     $aria_label = 'aria-label="' . __( 'No Author Archive Posts Found', 'avia_framework' ) . '"';
  334.     $aria_label = apply_filters( 'avf_aria_label_for_header', $aria_label, __FILE__, [] );
  335.     ?>
  336.    
  337.     <article class="entry">
  338.         <header class="entry-content-header" <?php echo $aria_label; ?>>
  339.             <?php echo "<{$heading} class='post-title entry-title {$css}'>" . __( 'Nothing Found', 'avia_framework' ) . "</{$heading}>"; ?>
  340.         </header>
  341.        
  342.         <p class="entry-content" <?php avia_markup_helper( array( 'context' => 'entry_content' ) ); ?>>
  343.             <?php _e( 'Sorry, no posts matched your criteria', 'avia_framework' ); ?>
  344.         </p>
  345.        
  346.         <footer class="entry-footer"></footer>
  347.     </article>
  348.    
  349. <?php
  350. }
Advertisement
Add Comment
Please, Sign In to add comment