<?php
if( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
/**
* Custom loop-author.php for Child-Theme (Enfold 7.1.3 compatible)
* Uses Grid or List Layout
* Place this file in: /wp-content/themes/enfold-child/includes/loop-author.php
* CSS file: /wp-content/themes/enfold-child/includes/loop-author.css
*/
// Load CSS only once
if( ! wp_style_is( 'enfold-child-loop-author', 'enqueued' ) ) {
$css_file = get_stylesheet_directory_uri() . '/includes/loop-author.css';
$css_path = get_stylesheet_directory() . '/includes/loop-author.css';
// Only load if file exists
if( file_exists( $css_path ) ) {
wp_enqueue_style( 'enfold-child-loop-author', $css_file, array(), filemtime( $css_path ) );
}
}
global $avia_config, $post_loop_count;
if( empty( $post_loop_count ) ) {
$post_loop_count = 1;
}
// Default arguments for Author Loop
$default_args = array(
'type' => 'grid',
'columns' => 4,
'items' => get_option('posts_per_page', 12), // WordPress setting, fallback: 12
'contents' => 'excerpt_read_more',
'preview_mode' => 'auto',
'image_size' => 'portfolio',
'paginate' => 'yes',
'class' => '',
'show_modified_date' => 'no', // 'yes' or 'no' - shows "Updated: XX" if post was modified
'orderby' => 'date', // 'date', 'modified', 'title', 'rand', 'comment_count', 'menu_order'
'order' => 'DESC', // 'DESC' (newest first) or 'ASC' (oldest first)
'fallback_image' => 'placeholder', // URL to fallback image or 'placeholder' for grey area with icon
'post_types' => array('post'), // Array: array('post'), array('portfolio'), or array('post', 'portfolio')
);
/**
* Filter for Author Loop arguments
*
* @param array $default_args Default arguments
* @param string $context Always 'author' for this loop
* @return array Filtered arguments
*/
$atts = apply_filters( 'avf_author_loop_args', $default_args, 'author' );
// Check if we got posts to display (uses the WordPress main query):
if( have_posts() )
{
// Container start - different classes for Grid vs. List
$container_class = 'av-author-loop-container';
if( $atts['type'] == 'grid' ) {
$container_class .= ' av-author-grid-container av-author-grid';
// Add column class (only for grid)
$container_class .= ' av-columns-' . $atts['columns'];
} else {
$container_class .= ' av-author-list-container av-author-list';
}
// Add custom class from filter
if( ! empty( $atts['class'] ) ) {
$container_class .= ' ' . esc_attr( $atts['class'] );
}
/**
* Filter for additional CSS classes
*/
$container_class = apply_filters( 'avf_author_loop_classes', $container_class, 'author', $atts );
echo '<div class="' . esc_attr( $container_class ) . '">';
while( have_posts() )
{
the_post();
$post_id = get_the_ID();
$image_size = $atts['image_size'];
$post_format = get_post_format() ? get_post_format() : 'standard';
// Get image or use fallback
$thumbnail = get_the_post_thumbnail( $post_id, $image_size );
// If no thumbnail and fallback is defined
if( empty( $thumbnail ) && ! empty( $atts['fallback_image'] ) ) {
if( $atts['fallback_image'] == 'placeholder' ) {
// Grey area with icon
$thumbnail = '<div class="av-author-placeholder-image">';
$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">';
$thumbnail .= '<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>';
$thumbnail .= '<circle cx="8.5" cy="8.5" r="1.5"></circle>';
$thumbnail .= '<polyline points="21 15 16 10 5 21"></polyline>';
$thumbnail .= '</svg>';
$thumbnail .= '</div>';
} else {
// Custom fallback image URL
$thumbnail = '<img src="' . esc_url( $atts['fallback_image'] ) . '" alt="' . esc_attr( get_the_title() ) . '" />';
}
}
// Content based on setting
$show_content = '';
$show_title = true;
$show_read_more = false;
// Determine what to show based on contents setting
switch( $atts['contents'] ) {
case 'title':
// Only title (default: show_title already true)
break;
case 'title_read_more':
// Title and read more
$show_read_more = true;
break;
case 'only_excerpt':
// Only excerpt, no title
$show_title = false;
$show_content = get_the_excerpt();
break;
case 'only_excerpt_read_more':
// Excerpt and read more, no title
$show_title = false;
$show_content = get_the_excerpt();
$show_read_more = true;
break;
case 'excerpt':
// Title and excerpt (default)
$show_content = get_the_excerpt();
break;
case 'excerpt_read_more':
// Title, excerpt and read more
$show_content = get_the_excerpt();
$show_read_more = true;
break;
default:
// Fallback to excerpt
$show_content = get_the_excerpt();
break;
}
// Gather meta info
$meta_info = array();
$meta_separator = '<span class="text-sep">/</span>';
// Published Date (from Enfold settings)
if( 'blog-meta-date' == avia_get_option( 'blog-meta-date' ) ) {
$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>';
}
// Modified Date (optional, controlled via filter)
if( $atts['show_modified_date'] == 'yes' ) {
$published_date = get_the_date( get_option('date_format'), $post_id );
$modified_date = get_the_modified_date( get_option('date_format'), $post_id );
// Only show if actually modified
if( $published_date != $modified_date ) {
$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>';
}
}
if( 'blog-meta-comments' == avia_get_option( 'blog-meta-comments' ) ) {
if( get_comments_number() != '0' && comments_open() ) {
ob_start();
comments_popup_link(
"0 " . __( 'Comments', 'avia_framework' ),
"1 " . __( 'Comment' , 'avia_framework' ),
"% " . __( 'Comments', 'avia_framework' ),
'comments-link',
__( 'Comments Disabled', 'avia_framework' )
);
$meta_info['comments'] = '<span class="comment-container minor-meta">' . ob_get_clean() . '</span>';
}
}
$taxonomies = get_object_taxonomies( get_post_type( $post_id ) );
$cats = '';
$excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array( 'post_tag', 'post_format' ) );
$excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $post_id ), $post_id, 'loop-author' );
if( ! empty( $taxonomies ) ) {
foreach( $taxonomies as $taxonomy ) {
if( ! in_array( $taxonomy, $excluded_taxonomies ) ) {
$cats .= get_the_term_list( $post_id, $taxonomy, '', ', ','' ) . ' ';
}
}
}
if( 'blog-meta-category' == avia_get_option( 'blog-meta-category' ) && ! empty( $cats ) ) {
$meta_info['categories'] = '<span class="blog-categories minor-meta">' . __( 'in', 'avia_framework') . ' ' . trim( $cats ) . '</span>';
}
$meta_info = apply_filters( 'avf_post_metadata_array', $meta_info, 'loop-author' );
// Parity for columns (only relevant for grid)
$parity = '';
$first = $post_loop_count == 1 ? 'first' : '';
// Grid Layout
if( $atts['type'] == 'grid' ) {
?>
<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; ?>">
<div class="av-author-grid-item">
<?php if( $thumbnail ): ?>
<a href="<?php the_permalink(); ?>" class="av-author-grid-image-link" title="<?php echo esc_attr( get_the_title() ); ?>">
<div class="av-author-grid-image">
<?php echo $thumbnail; ?>
<?php if( has_post_thumbnail( $post_id ) ): ?>
<div class="av-author-grid-overlay"></div>
<?php endif; ?>
</div>
</a>
<?php endif; ?>
<div class="av-author-grid-content">
<header class="entry-content-header">
<?php if( $show_title ): ?>
<h3 class="av-author-grid-title entry-title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h3>
<?php endif; ?>
<?php if( ! empty( $meta_info ) ): ?>
<span class="av-author-grid-meta">
<?php echo implode( $meta_separator, $meta_info ); ?>
</span>
<?php endif; ?>
</header>
<?php if( ! empty( $show_content ) ): ?>
<div class="av-author-grid-excerpt entry-content">
<?php echo wpautop( $show_content ); ?>
</div>
<?php endif; ?>
</div>
<?php if( $show_read_more ): ?>
<div class="av-author-grid-read-more">
<a href="<?php the_permalink(); ?>" class="more-link"><?php _e('Read more', 'avia_framework'); ?><span class="more-link-arrow">→</span></a>
</div>
<?php endif; ?>
</div>
</article>
<?php
}
// List Layout
else {
?>
<article class="av-author-list-item post-entry post-entry-<?php echo $post_id; ?> <?php echo $first; ?> post-entry-type-<?php echo $post_format; ?>">
<?php if( $thumbnail ): ?>
<div class="av-author-list-image">
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( get_the_title() ); ?>">
<?php echo $thumbnail; ?>
</a>
</div>
<?php endif; ?>
<div class="av-author-list-content">
<header class="entry-content-header">
<?php if( $show_title ): ?>
<h3 class="av-author-list-title entry-title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h3>
<?php endif; ?>
<?php if( ! empty( $meta_info ) ): ?>
<span class="av-author-list-meta">
<?php echo implode( $meta_separator, $meta_info ); ?>
</span>
<?php endif; ?>
</header>
<?php if( ! empty( $show_content ) ): ?>
<div class="av-author-list-excerpt entry-content">
<?php echo wpautop( $show_content ); ?>
</div>
<?php endif; ?>
<?php if( $show_read_more ): ?>
<div class="av-author-list-read-more">
<a href="<?php the_permalink(); ?>" class="more-link"><?php _e('Read more', 'avia_framework'); ?><span class="more-link-arrow">→</span></a>
</div>
<?php endif; ?>
</div>
</article>
<?php
}
$post_loop_count++;
}
echo '</div>'; // End container
// Pagination
if( ! isset( $avia_config['remove_pagination'] ) && $atts['paginate'] == 'yes' ) {
echo '<div class="av-author-pagination">';
echo avia_pagination( '', 'nav' );
echo '</div>';
}
}
else
{
// Nothing found
$default_heading = 'h1';
$args = array(
'heading' => $default_heading,
'extra_class' => ''
);
$args = apply_filters( 'avf_customize_heading_settings', $args, 'loop_author::nothing_found', array() );
$heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
$css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
$aria_label = 'aria-label="' . __( 'No Author Archive Posts Found', 'avia_framework' ) . '"';
$aria_label = apply_filters( 'avf_aria_label_for_header', $aria_label, __FILE__, [] );
?>
<article class="entry">
<header class="entry-content-header" <?php echo $aria_label; ?>>
<?php echo "<{$heading} class='post-title entry-title {$css}'>" . __( 'Nothing Found', 'avia_framework' ) . "</{$heading}>"; ?>
</header>
<p class="entry-content" <?php avia_markup_helper( array( 'context' => 'entry_content' ) ); ?>>
<?php _e( 'Sorry, no posts matched your criteria', 'avia_framework' ); ?>
</p>
<footer class="entry-footer"></footer>
</article>
<?php
}
Comments
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎