• Resolved nickaster

    (@nickaster)


    Okay, so this might be a crazy hack, might not.

    I have a particular category archive page which I want to use as a sort of hacked author archive page. Lord, never mind the reasons. But here’s what i want.

    It’s category-XXX.php so when someone askes for category XXX it calls the template up.

    BUT!

    I don’t actually want to display the posts from category XXX. Instead, I want to display the posts from AUTHOR 123.

    What do I have to do to edit the standard code for a category archive to force only posts by Author 123 instead?

    Many thanks!!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • the simplest way would be to have only author 123 post in category-xxx

    or check this out: https://codex.www.ads-software.com/Template_Tags/query_posts#Author_Parameters

    Thread Starter nickaster

    (@nickaster)

    Hmm… thanks.

    So question one – is the template always going to automatically set itself to show ONLY category XXX before it even loads? Ie – is that controlled by code on the page, or is that decision made earlier when WP chooses the template?

    I’m assuming the latter might be the case… so are you saying this is difficult to override?

    You can over-ride the posts being shown on the page… or i don’t see why you can’t….

    Create a regular query_posts loop (in your category-xx.php file), except, place this before the loop..

    <?php wp_reset_query(); ?>

    Then do whatever you want in your own query_posts… so for example…

    <?php query_posts('author=1'); ?>

    Would grab all posts by the author with an ID of 1.

    That should work in theory. You’ll still of course need to do all the regular while(have_posts() etc… but i assume you get the point.. ??

    Thread Starter nickaster

    (@nickaster)

    Okay excellent. I’m not sure it works, however.

    I pulled this totally generic loop code from here:
    https://justintadlock.com/blog/wp-content/uploads/2009/01/the-loop.txt

    Then I added the <?php wp_reset_query(); ?> to the top of the loop and it still only pulls from the category XXX

    So it looks to me like you can’t override it? Is there a better example of the most generic loop possible that I could tinker with?

    Thanks!

    Did you do the query_posts line after the reset?

    <?php
    wp_reset_query();
    query_posts('newparametershere');
     ?>

    Where “newparametershere” is a set of new parameters.

    I’ve just tested it (for clarity) and it does work.

    I created a file called category-1.php (i only have 1 post in that category), then plonked in a basic loop..

    <?php if (have_posts()) : ?>
    	<?php while (have_posts()) : the_post(); ?>
    	<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><span class="postTitle"><?php the_title(); ?></span></h2>
    	<div class="entry"><?php the_content(); ?></div>
    	</div>
    	<?php endwhile;?>
    <?php endif; ?>

    Loaded the page, 1 post, as expected.

    So then i updated the code to..

    <?php
    wp_reset_query();
    query_posts('author=2');
    
    if (have_posts()) : ?>
    	<?php while (have_posts()) : the_post(); ?>
    	<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><span class="postTitle"><?php the_title(); ?></span></h2>
    	<div class="entry"><?php the_content(); ?></div>
    	</div>
    	<?php endwhile;?>
    <?php endif; ?>

    Loaded the page up again, no posts… which is to be expected, there’s no author 2 on my test install.

    I wanted to be sure so i updated the query_posts to..

    query_posts('category_name=Templates');

    And loaded the page…

    I saw posts from the Templates category..

    So it definately works mate.. ??

    Thread Starter nickaster

    (@nickaster)

    Brilliant! Thank you. I’m slowly learning this code. It’s a long curve with no php experience to speak of and these examples are REALLY helpful.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘A Very Special Category Archive Page’ is closed to new replies.