Template for Single Author

There seems to be no ability to create templates for the single author template. Am I missing something? I could create a CPT but I would rather have a template that targets the single author page instead.

Technically this is not a single but an archive template (as it shows all the posts from that author). So you create an archive page with the following conditions:

Indeed! Thanks. But unfortunately, this doesn’t allow for editing the single author (author.php) template. Seems like a feature request needs to be made. I’ve put it on the idea board.

It would be extremely nice if this feature could be edited. thx

image

{current_author_id}

hide or show your design section depending on the author id. easy

// Adds a new tag 'current_author_id' to the Bricks Builder dynamic tags list.
add_filter( 'bricks/dynamic_tags_list', 'add_current_author_id_tag_to_builder' );
function add_current_author_id_tag_to_builder( $tags ) {
    $tags[] = [
        'name'  => 'current_author_id',
        'label' => 'Current Author ID',
        'group' => 'Author Data',
    ];

    return $tags;
}

// Retrieves the current author ID on an author archive page.
function get_current_author_id() {
    return is_author() ? get_queried_object_id() : '';
}

// Renders the 'current_author_id' tag by fetching the current author ID.
add_filter( 'bricks/dynamic_data/render_tag', 'render_current_author_id_tag', 10, 3 );
function render_current_author_id_tag( $tag, $post, $context = 'text' ) {
    if ( $tag === 'current_author_id' ) {
        return get_current_author_id();
    }
    return $tag;
}

// Replaces the '{current_author_id}' placeholder in content with the actual current author ID.
add_filter( 'bricks/dynamic_data/render_content', 'render_current_author_id_in_content', 10, 3 );
add_filter( 'bricks/frontend/render_data', 'render_current_author_id_in_content', 10, 2 );
function render_current_author_id_in_content( $content, $post, $context = 'text' ) {
    if ( strpos( $content, '{current_author_id}' ) !== false ) {
        $author_id = get_current_author_id();
        $content = str_replace( '{current_author_id}', $author_id, $content );
    }
    return $content;
}

1 Like

Well done. Thank you!