Guenni007 icon

loop-about-author

Guenni007 | PRO | 11/21/25 10:28:41 PM UTC | 0 ⭐ | 11828 👁️ | Never ⏰ | []
PHP |

4.4 KB

|

None

|

0 👍

/

0 👎

<?php
 
 
if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
 
/**
 * Custom loop-about-author.php für Child-Theme
 * Zählt Posts + Portfolio-Items für die Author-Bio
 * Platziere diese Datei in: /wp-content/themes/enfold-child/includes/loop-about-author.php
 */
 
global $avia_config;
$author_id = get_query_var( 'author' );
if( empty( $author_id ) )
{
    $author_id = get_the_author_meta( 'ID' );
}
$context = 'loop-about-author.php';
$description_ori = get_the_author_meta( 'description', $author_id );
/**
 * Filter author data
 *
 * @param string
 * @param int $author_id
 * @param string $context       added with 4.7.5.1
 * @return string
 */
$name = apply_filters( 'avf_author_name', get_the_author_meta( 'display_name', $author_id ), $author_id, $context );
$email = apply_filters( 'avf_author_email', get_the_author_meta( 'email', $author_id ), $author_id, $context );
$description = apply_filters( 'avf_author_description', $description_ori, $author_id, $context );
$gravatar_alt = esc_html( $name );
$gravatar = get_avatar( $email, '81', '', $gravatar_alt );
 
// Keep plain name for translations
$name_plain = $name;
 
$name = "<span class='author-box-name' " . avia_markup_helper( array( 'context' => 'author_name', 'echo' => false ) ) . '>'. $name . '</span>';
$heading = __( 'About', 'avia_framework' ) . ' ' . $name;
$default_heading = 'h3';
$args = array(
            'heading'       => $default_heading,
            'extra_class'   => ''
        );
/**
 * @since 4.5.5
 * @return array
 */
$args = apply_filters( 'avf_customize_heading_settings', $args, 'loop_default_author', array() );
$heading1 = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
$css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
 
// Count posts for all defined post types
$default_args = array( 'post_types' => array('post') );
$atts = apply_filters( 'avf_author_loop_args', $default_args, 'author' );
 
$cnt_posts = 0;
$post_type_counts = array();
 
if( ! empty( $atts['post_types'] ) && is_array( $atts['post_types'] ) ) {
    foreach( $atts['post_types'] as $post_type ) {
        $count = count_user_posts( $author_id, $post_type );
        if( $count > 0 ) {
            $cnt_posts += $count;
            
            // Get post type label
            $post_type_obj = get_post_type_object( $post_type );
            $post_type_label = $post_type_obj ? $post_type_obj->labels->name : $post_type;
            
            $post_type_counts[] = $count . ' ' . $post_type_label;
        }
    }
} else {
    // Fallback: count only posts
    $cnt_posts = count_user_posts( $author_id );
}
 
// Build entry count text
$entry_text = '';
if( $cnt_posts > 0 ) {
    $breakdown = ! empty( $post_type_counts ) ? ' (' . implode( ', ', $post_type_counts ) . ')' : '';
    // Use existing Enfold translation string - breakdown at the end
    $entry_text = '<br />' . sprintf( __( 'But we are proud to say that %s contributed %s entries already.', 'avia_framework' ), $name, $cnt_posts ) . '<br />' . $breakdown;
}
 
if( empty( $description ) )
{
    $description  = __( 'This author has not written his bio yet.', 'avia_framework' );
    $description .= $entry_text;
    if( current_user_can( 'edit_users' ) || get_current_user_id() == $author_id )
    {
        $description .= "<br /><a href='" . admin_url( 'profile.php?user_id=' . $author_id ) . "'>" . __( 'Edit the profile description here.', 'avia_framework' ) . '</a>';
    }
}
else
{
    // Bio exists - append entry count
    $description .= $entry_text;
}
/**
 * Filter final output of author description or skip completly
 *
 * @since 4.7.5.1
 * @param string $description
 * @param string $description_ori
 * @param int $author_id
 * @return string|false                 false to skip output completely
 */
$description = apply_filters( 'avf_author_description_loop_about', $description, $description_ori, $author_id );
if( false === $description )
{
    return;
}
echo '<section class="author-box" ' . avia_markup_helper( array( 'context' => 'author', 'echo' => false ) ) . '>';
echo    "<span class='post-author-format-type blog-meta'><span class='rounded-container'>{$gravatar}</span></span>";
echo    "<div class='author_description '>";
echo        "<{$heading1} class='author-title {$css}'>{$heading}</{$heading1}>";
echo        "<div class='author_description_text'" . avia_markup_helper( array( 'context' => 'description', 'echo' => false ) ) . '>' . wpautop( $description ) . '</div>';
echo        '<span class="author-extra-border"></span>';
echo    '</div>';
echo '</section>';
 
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎