Guenni007

loop-author

Nov 19th, 2025 (edited)
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.26 KB | None | 0 0
  1. <?php
  2.  
  3. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  4.  
  5. /**
  6.  * Custom loop-author.php for child theme (Enfold 7.1.3 compatible)
  7.  * Place this file in: /wp-content/themes/enfold-child/includes/loop-author.php
  8.  */
  9.  
  10. global $avia_config, $post_loop_count;
  11.  
  12. if( empty( $post_loop_count ) ) {
  13.     $post_loop_count = 1;
  14. }
  15.  
  16. // Standard Argumente für Author Loop
  17. $default_args = array(
  18.     'type'              => 'grid',
  19.     'columns'           => 4,
  20.     'items'             => get_option('posts_per_page', 12), // WordPress Einstellung, Fallback: 12
  21.     'contents'          => 'excerpt',
  22.     'preview_mode'      => 'auto',
  23.     'image_size'        => 'portfolio',
  24.     'paginate'          => 'yes',
  25.     'class'             => '',
  26.     'show_modified_date' => 'no',  // 'yes' oder 'no' - zeigt "Updated: XX" wenn Post bearbeitet wurde
  27.     'orderby'           => 'date',  // 'date', 'modified', 'title', 'rand', 'comment_count', 'menu_order'
  28.     'order'             => 'DESC',  // 'DESC' (neueste zuerst) oder 'ASC' (älteste zuerst)
  29. );
  30.  
  31. /**
  32.  * Filter für Author Loop Argumente
  33.  *
  34.  * @param array $default_args   Die Standard-Argumente
  35.  * @param string $context       Immer 'author' für diese Loop
  36.  * @return array                Gefilterte Argumente
  37.  */
  38. $atts = apply_filters( 'avf_author_loop_args', $default_args, 'author' );
  39.  
  40. // Check if we got posts to display (nutzt die WordPress Haupt-Query):
  41. if( have_posts() )
  42. {
  43.     // Grid Container starten
  44.     $grid_class = 'av-author-grid-container';
  45.    
  46.     if( $atts['type'] == 'grid' ) {
  47.         $grid_class .= ' av-author-grid';
  48.        
  49.         // Spalten-Klasse hinzufügen
  50.         $grid_class .= ' av-columns-' . $atts['columns'];
  51.     }
  52.    
  53.     /**
  54.      * Filter für zusätzliche CSS Klassen
  55.      */
  56.     $grid_class = apply_filters( 'avf_author_loop_classes', $grid_class, 'author', $atts );
  57.    
  58.     echo '<div class="' . esc_attr( $grid_class ) . '">';
  59.    
  60.     while( have_posts() )
  61.     {
  62.         the_post();
  63.        
  64.         $post_id = get_the_ID();
  65.         $image_size = $atts['image_size'];
  66.         $post_format = get_post_format() ? get_post_format() : 'standard';
  67.        
  68.         // Image holen
  69.         $thumbnail = get_the_post_thumbnail( $post_id, $image_size );
  70.        
  71.         // Content basierend auf Einstellung
  72.         $show_content = '';
  73.         if( in_array( $atts['contents'], array('excerpt', 'excerpt_read_more') ) ) {
  74.             $show_content = get_the_excerpt();
  75.         } elseif( $atts['contents'] == 'content' ) {
  76.             $show_content = get_the_content();
  77.         }
  78.        
  79.         // Meta Info sammeln
  80.         $meta_info = array();
  81.         $meta_separator = '<span class="text-sep">/</span>';
  82.        
  83.         // Published Date (aus Enfold Einstellungen)
  84.         if( 'blog-meta-date' == avia_get_option( 'blog-meta-date' ) ) {
  85.             $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>';
  86.         }
  87.        
  88.         // Modified Date (optional über Filter steuerbar)
  89.         if( $atts['show_modified_date'] == 'yes' ) {
  90.             $published_date = get_the_date( get_option('date_format'), $post_id );
  91.             $modified_date = get_the_modified_date( get_option('date_format'), $post_id );
  92.            
  93.             // Nur anzeigen wenn tatsächlich bearbeitet wurde
  94.             if( $published_date != $modified_date ) {
  95.                 $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>';
  96.             }
  97.         }
  98.        
  99.         if( 'blog-meta-comments' == avia_get_option( 'blog-meta-comments' ) ) {
  100.             if( get_comments_number() != '0' || comments_open() ) {
  101.                 ob_start();
  102.                 comments_popup_link(
  103.                     "0 " . __( 'Comments', 'avia_framework' ),
  104.                     "1 " . __( 'Comment' , 'avia_framework' ),
  105.                     "% " . __( 'Comments', 'avia_framework' ),
  106.                     'comments-link',
  107.                     __( 'Comments Disabled', 'avia_framework' )
  108.                 );
  109.                 $meta_info['comments'] = '<span class="comment-container minor-meta">' . ob_get_clean() . '</span>';
  110.             }
  111.         }
  112.        
  113.         $taxonomies = get_object_taxonomies( get_post_type( $post_id ) );
  114.         $cats = '';
  115.         $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array( 'post_tag', 'post_format' ) );
  116.         $excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $post_id ), $post_id, 'loop-author' );
  117.        
  118.         if( ! empty( $taxonomies ) ) {
  119.             foreach( $taxonomies as $taxonomy ) {
  120.                 if( ! in_array( $taxonomy, $excluded_taxonomies ) ) {
  121.                     $cats .= get_the_term_list( $post_id, $taxonomy, '', ', ','' ) . ' ';
  122.                 }
  123.             }
  124.         }
  125.        
  126.         if( 'blog-meta-category' == avia_get_option( 'blog-meta-category' ) && ! empty( $cats ) ) {
  127.             $meta_info['categories'] = '<span class="blog-categories minor-meta">' . __( 'in', 'avia_framework') . ' ' . trim( $cats ) . '</span>';
  128.         }
  129.        
  130.         $meta_info = apply_filters( 'avf_post_metadata_array', $meta_info, 'loop-author' );
  131.        
  132.         // Parity für Spalten (nicht mehr nötig bei Grid, aber für Kompatibilität)
  133.         $parity = '';
  134.         $first = $post_loop_count == 1 ? 'first' : '';
  135.        
  136.         ?>
  137.         <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; ?>">
  138.            
  139.             <div class="av-author-grid-item">
  140.                
  141.                 <a href="<?php the_permalink(); ?>" class="av-author-grid-image-link" title="<?php echo esc_attr( get_the_title() ); ?>">
  142.                     <?php if( $thumbnail ): ?>
  143.                     <div class="av-author-grid-image">
  144.                         <?php echo $thumbnail; ?>
  145.                         <div class="av-author-grid-overlay"></div>
  146.                     </div>
  147.                     <?php endif; ?>
  148.                 </a>
  149.                
  150.                 <div class="av-author-grid-content">
  151.                     <header class="entry-content-header">
  152.                         <h3 class="av-author-grid-title entry-title">
  153.                             <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  154.                         </h3>
  155.                        
  156.                         <?php if( ! empty( $meta_info ) ): ?>
  157.                         <span class="av-author-grid-meta">
  158.                             <?php echo implode( $meta_separator, $meta_info ); ?>
  159.                         </span>
  160.                         <?php endif; ?>
  161.                     </header>
  162.                    
  163.                     <?php if( ! empty( $show_content ) ): ?>
  164.                     <div class="av-author-grid-excerpt entry-content">
  165.                         <?php echo wpautop( $show_content ); ?>
  166.                     </div>
  167.                     <?php endif; ?>
  168.                 </div>
  169.                
  170.                 <?php if( $atts['contents'] == 'excerpt_read_more' ): ?>
  171.                 <div class="av-author-grid-read-more">
  172.                     <a href="<?php the_permalink(); ?>" class="more-link"><?php _e('Read more', 'avia_framework'); ?><span class="more-link-arrow"></span></a>
  173.                 </div>
  174.                 <?php endif; ?>
  175.                
  176.             </div>
  177.            
  178.         </article>
  179.         <?php
  180.        
  181.         $post_loop_count++;
  182.     }
  183.    
  184.     echo '</div>'; // Ende Grid Container
  185.    
  186.     // Pagination - genau wie in loop-index.php
  187.     if( ! isset( $avia_config['remove_pagination'] ) && $atts['paginate'] == 'yes' ) {
  188.         echo '<div class="av-author-pagination">';
  189.         echo avia_pagination( '', 'nav' );
  190.         echo '</div>';
  191.     }
  192. }
  193. else
  194. {
  195.     // Nichts gefunden
  196.     $default_heading = 'h1';
  197.     $args = array(
  198.         'heading'       => $default_heading,
  199.         'extra_class'   => ''
  200.     );
  201.    
  202.     $args = apply_filters( 'avf_customize_heading_settings', $args, 'loop_author::nothing_found', array() );
  203.    
  204.     $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  205.     $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  206.    
  207.     $aria_label = 'aria-label="' . __( 'No Author Archive Posts Found', 'avia_framework' ) . '"';
  208.     $aria_label = apply_filters( 'avf_aria_label_for_header', $aria_label, __FILE__, [] );
  209.     ?>
  210.    
  211.     <article class="entry">
  212.         <header class="entry-content-header" <?php echo $aria_label; ?>>
  213.             <?php echo "<{$heading} class='post-title entry-title {$css}'>" . __( 'Nothing Found', 'avia_framework' ) . "</{$heading}>"; ?>
  214.         </header>
  215.        
  216.         <p class="entry-content" <?php avia_markup_helper( array( 'context' => 'entry_content' ) ); ?>>
  217.             <?php _e( 'Sorry, no posts matched your criteria', 'avia_framework' ); ?>
  218.         </p>
  219.        
  220.         <footer class="entry-footer"></footer>
  221.     </article>
  222.    
  223. <?php
  224. }
Advertisement
Add Comment
Please, Sign In to add comment