Community Forums › Forums › Archived Forums › General Discussion › How do I make a custom loop on author.php?
Tagged: author page
- This topic has 6 replies, 3 voices, and was last updated 8 years, 11 months ago by carasmo.
-
AuthorPosts
-
February 22, 2016 at 4:11 pm #179654songdogtechParticipant
How do I make an author.php page template with a custom loop?
I want to simply list all post title and dates, and not excerpts, author bio boxes or anything else. So I need to unhook the Genesis loop and run my own loop on author.php. But I've tried that with the page template below, and I end up with broken HTML5.
I'm using this in author.php right now:
<?php remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'author_loop' ); function author_loop() { // my loop to list all post titles and dates wp_reset_query(); } genesis();
But that doesn't give me the HTML5 output of a normal page, like this:
<div class="site-inner"> <div class="content-sidebar-wrap"> <main class="content" id="genesis-content"> <article class="post-557 page type-page status-closed entry articles" itemscope itemtype="http://schema.org/CreativeWork"> <header class="entry-header"> <h1 class="entry-title" itemprop="headline">Page Title</h1> </header> <div class="entry-content" itemprop="text"> (post excerpts
What I get is broken HTML5, missing the article and header divs, like this:
<div class="site-inner"> <div class="content-sidebar-wrap"> <main class="content" id="genesis-content"> <div class="archive-description author-archive-description author-description"> <h1 class="archive-title">Archive Title</h1> </div> (the text of my author loop)
The sidebars are in place, so the full Genesis loop is running. I just want to replace the default author.php loop with my own.
Any ideas?
February 22, 2016 at 5:03 pm #179657carasmoParticipantI just tested a custom loop with Bill's code (https://gist.github.com/billerickson/3218052) and all the structural markup (site-inner etc, is there and the page has no broken html)
<?php /** * Template Name: Author Page */ function themeprefix_author_loop() { global $post; // arguments, adjust as needed $args = array( 'post_type' => 'post', 'posts_per_page' => 1, 'post_status' => 'publish', 'paged' => get_query_var( 'paged' ) ); /* Overwrite $wp_query with our new query. The only reason we're doing this is so the pagination functions work, since they use $wp_query. If pagination wasn't an issue, use: https://gist.github.com/3218106 */ global $wp_query; $wp_query = new WP_Query( $args ); if ( have_posts() ) : echo '<ul>'; while ( have_posts() ) : the_post(); echo '<li>' . get_the_title() . '</li>'; endwhile; echo '</ul>'; do_action( 'genesis_after_endwhile' ); endif; wp_reset_query(); } remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'themeprefix_author_loop' ); genesis();
February 22, 2016 at 8:45 pm #179679songdogtechParticipantThanks, but I tried that already, and that page template is functionally no different than mine. The key here is that my file is named author.php, the default name for the author template in WordPress, and Genesis themes don't have an author.php file, as far as I have seen, while many other WP themes do. This is with the Genesis Sample theme.
February 23, 2016 at 5:07 am #179699carasmoParticipantMine is a custom child theme from scratch and all of the structural markup is there. Using Bill's code on a page named author.php, I have put a class on the loop to make it easier to see and here's the parsed html:
I used the exact code from Bill's gist.
<div class="site-inner"> <div class="content-sidebar-wrap"> <main class="content" id="genesis-content"> <div class="archive-description author-archive-description author-description"> <h1 class="archive-title">Christina</h1> </div> <ul class="author-posts"> <li>Sample Post With Threaded Comments</li> <li>Sample Post With Image Centered</li> <li>Sample Post With an Ordered List</li> <li>Sample Post With a Blockquote</li> <li>Sample Post With a Table</li> <li>Sample Post With Headlines</li> <li>Sample Post With Image Aligned Right</li> </ul> </main> </div> </div> <footer class="site-footer" itemscope itemtype="http://schema.org/WPFooter"> <div class="wrap"> ... </div> </footer> </div> <!-- ends .site-container -->
February 23, 2016 at 7:01 am #179707carasmoParticipantI looked in loops.php in Genesis and this works like a charm, including the regular markup that goes on each post itself.
https://gist.github.com/carasmo/ff6e0d9687a7addfe8bd -- for author.php -- shows only the titles as h2 tags but I added a filter to turn them into h3 tags
https://gist.github.com/carasmo/70a4fd9cc27d5822e03a -- for functions.php file if you want to add pagination to any archive type besides the blog/index it goes in your functions and you don't need to do anything in the author.php file.
February 23, 2016 at 7:54 am #179711Genesis DeveloperMemberYou will always use the
genesis_custom_loop()
function. Otherwise you can get lot of issue. You can try this onceremove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'author_loop' ); function author_loop() { $args = array(); // write custom query args in this array // now pass this $args variable in genesis_custom_loop function like this genesis_custom_loop( $args ); } genesis();
Now you will use add_action or remove_action for any custom content for your author. Hope it helps.
February 23, 2016 at 8:23 am #179712carasmoParticipantI just tested my gist https://gist.github.com/carasmo/ff6e0d9687a7addfe8bd extensively with debug on. There is no need for genesis_custom_loop... in this case of making a template author.php.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.