How to create archive template for user roles?

Hey guys, does anyone know how to create archive templates for specific roles, not just “Author”?

If I go to Templates > Archive > author I can assign my author role, but how would I assign other roles?
I tried looking online but can’t seem to find information on this.

Or just a template for users
why is it possible to query users if not to create a singular user template

Hey, guys sorry haven’t updated this post in a while, Thomas and his team got back to me a while back about this issue.

You will need a code snippet plugin that you can input this code

This is to display Author Roles

<?php 
add_filter( 'builder/settings/template/controls_data', function( $data ) {
  // Do something
 
  return $data;
});

add_filter( 'builder/settings/page/controls_data', function( $data ) {
  // Do something
 
  return $data;
});

add_filter( 'builder/settings/template/controls_data', function( $data ) {
  // Get all the site user roles
  $all_roles = wp_roles()->roles;

  $roles = [];

  foreach ( $all_roles as $role => $role_data ) {
    $roles[ $role ] = $role_data['name'];
  }

  // Add control to select the user roles for an author archive template type
  $data['controls']['templateConditions']['fields']['archiveAuthorRoles'] = [
    'type'        => 'select',
    'label'       => esc_html__( 'Author roles', 'bricks' ),
    'options'     => $roles,
    'multiple'    => true,
    'placeholder' => esc_html__( 'Select role', 'bricks' ),
    'description' => esc_html__( 'Leave empty to apply template to all roles.', 'bricks' ),
    'required'    => [ 'archiveType', '=', 'author' ],
  ];

  return $data;
} );

In a separate code snippet input this as well to display Author Role Scores:

<?php 
add_filter( 'bricks/screen_conditions/scores', function( $scores, $condition, $post_id, $preview_type ) {
  // Run custom logic to score the template/theme style $condition
  // $scores[] = 5; 
 
  return $scores;
}, 10, 4 );

add_filter( 'bricks/screen_conditions/scores', function( $scores, $condition, $post_id, $preview_type ) {
  if ( is_author() && $condition['main'] === 'archiveType' && isset( $condition['archiveType'] ) && in_array( 'author', $condition['archiveType'] ) && isset( $condition['archiveAuthorRoles'] ) ) { 
    $user = get_queried_object();

    if ( ! empty( $user->roles ) && is_array( $user->roles ) ) {
      foreach ( $user->roles as $role_name ) {
        if ( in_array( $role_name, $condition['archiveAuthorRoles'] ) ) {
          $scores[] = 9;
        }
      }
    }
  }

  return $scores;
}, 10, 4 );
1 Like

hi @aslotta
this code doesn’t seem to work. it applies the user template to all user roles even when you select specific user role