Guenni007

loop-author

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