Guenni007

code-snippet

Nov 21st, 2025
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.66 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. // see https://kriesi.at/support/topic/how-to-customize-the-author-page/
  5.  
  6. // 1. Configure layout and settings
  7. add_filter( 'avf_author_loop_args', function( $atts, $context ) {
  8.     if( $context == 'author' ) {
  9.         $atts['type']               = 'grid';               // 'grid' or 'list' Layout
  10.         $atts['columns']            = 4;                    // Columns count
  11.         $atts['image_size']         = 'gallery';            // image size
  12.         $atts['contents']           = 'excerpt_read_more';  // Content-Type
  13.         $atts['items']              = -1;                   // Posts per page
  14.         $atts['paginate']           = 'no';                // Pagination on/off
  15.         $atts['show_modified_date'] = 'yes';               // 'yes' = shows "Updated: XX"
  16.         $atts['orderby']            = 'title';               // order by : 'date', 'modified', 'title', 'rand', 'comment_count'
  17.         $atts['order']              = 'DESC';               // order : 'DESC' (neueste/Z-A) oder 'ASC' (älteste/A-Z)
  18.         $atts['fallback_image']     = 'placeholder';      // URL to the fallback image,  'placeholder' for svg inside a gray background - or:
  19.     //  $atts['fallback_image']     = get_stylesheet_directory_uri() . '/images/fallback-image.jpg';  another possibility: upload a fall-back image
  20.     }
  21.     return $atts;
  22. }, 10, 2);
  23.  
  24.  
  25. // 2. IMPORTANT: Adjust query for pagination and sorting
  26. add_action( 'pre_get_posts', function( $query ) {
  27.     if( ! is_admin() && $query->is_main_query() && is_author() ) {
  28.         // Get the filtered arguments
  29.         $default_args = array(
  30.             'items'   => get_option('posts_per_page', 12),
  31.             'orderby' => 'date',
  32.             'order'   => 'DESC'
  33.         );
  34.         $atts = apply_filters( 'avf_author_loop_args', $default_args, 'author' );
  35.        
  36.         // setup for Query-Parameters
  37.         $query->set( 'posts_per_page', $atts['items'] );
  38.         $query->set( 'orderby', $atts['orderby'] );
  39.         $query->set( 'order', $atts['order'] );
  40.     }
  41. }, 1 );
  42.  
  43.  
  44. // Example: Different layouts for different authors
  45. /*
  46. add_filter( 'avf_author_loop_args', function( $atts, $context ) {
  47.     if( $context == 'author' ) {
  48.         $author_id = get_query_var( 'author' );
  49.        
  50.         // Individual configuration for specific authors
  51.         if( $author_id == 1 ) { // commonly the Admin
  52.             $atts['type']     = 'grid';
  53.             $atts['columns']  = 3;
  54.             $atts['contents'] = 'excerpt_read_more';
  55.         } else {
  56.             $atts['type']     = 'grid';
  57.             $atts['columns']  = 4;
  58.             $atts['contents'] = 'title';
  59.         }
  60.     }
  61.     return $atts;
  62. }, 10, 2);
  63. */
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment