Advertisement
kingBethal

Authors page

Feb 10th, 2021
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. <?php
  2. /**
  3.  * The template for displaying Author's pages.
  4.  */
  5. // GET CURRENT AUTHOR
  6. if (get_query_var('author')) {
  7.     global $wp_query;
  8.     $curauth = $wp_query->get_queried_object();
  9. }
  10.  
  11. // AUTHOR LINK
  12. $auth_link = esc_url(get_author_posts_url(false, $curauth->user_nicename));
  13.  
  14. // GET HEADER
  15. get_header();
  16. ?>
  17.  
  18. <div id="primary" class="content-area">
  19.     <main id="main" class="site-main" role="main">
  20.  
  21.         <div class="container">
  22.             <div class="row">
  23.  
  24.                 <div class="col-12 col-md-9 p-1 bg-white pt-2 mt-2 container-fluid">
  25.  
  26.                     <div class="row-fluid">
  27.  
  28.                         <!-- Posts -->  
  29.                         <div class="latest-posts">
  30.                             <?php
  31.                             $args = array(
  32.                                 'author' => $curauth->ID,
  33.                                 'post_type' => array('song', 'poem'), // get all post types
  34.                                 'posts_per_page' => 10 // // get 10 posts from all post types
  35.                             );
  36.                             query_posts($args);
  37.  
  38.                             if (have_posts()) : while (have_posts()) : the_post();
  39.                                     ?>
  40.                                     <!-- single post title, author -->
  41.                                     <div class="post-title">
  42.                                         <a href="<?php echo esc_url(get_permalink()); ?>">
  43.                                             <h4 class="text-title">
  44.                                                 <?php the_title(); ?>
  45.                                             </h4>
  46.                                         </a>
  47.                                         <span>Post by <?php echo the_author_meta('display_name'); ?></span>
  48.                                     </div>
  49.  
  50.                                     <?php
  51.                                 endwhile; // end loop
  52.                                 wp_reset_postdata(); // reset query
  53.                             endif;
  54.                             ?>
  55.                         </div>
  56.  
  57.                     </div>
  58.  
  59.                     <!-- LINK TO ALL POSTS -->
  60.                     <?php
  61.                     // IF TOTAL POSTS ARE MORE THAN 10; SHOW CURRENT AUTHORS ALL POSTS IN ARCHIVE PAGE
  62.                     if (($total = count_user_posts($curauth->ID, array('song', 'poem'))) > 10) {
  63.                         echo '<a href="' . $auth_link . '?post_type[]=song&post_type[]=poem">View All</a>';
  64.                     }
  65.                     ?>
  66.  
  67.  
  68.                 </div>
  69.  
  70.             </div><!-- #primary -->
  71.         </div>
  72.     </main><!-- #main -->
  73. </div>
  74.  
  75. <?php
  76. get_footer();
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement