WordPress.org

Ready to get started?Download WordPress

Forums

Specific user post pages (5 posts)

  1. MKULTRON
    Member
    Posted 3 years ago #

    I want my homepage to pull all the posts by the admin and I have two other pages to pull only specific posts from those authors.

    I thought I may be able to do this just by appending something in the querystring eg ?author=1 - can't remember exactly but I got it working for the main page. Problem came when I tried to add this to the URL at the end of my custom template pages for the other authors, it'd put in an extra slash and bring up a 404. I've tried a bit of logic instead to bring up specific authors posts but these give me blank pages.

    Any ideas? Would be much appreciated.

    Thanks
    MK

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    try it with a query posts before the loop

    <?php 
    
      // The Query
      query_posts( 'author=123' ); // author ID
    
      // The Loop
      while ( have_posts() ) : the_post();
      // rest of loop
    
    ?>
  3. MKULTRON
    Member
    Posted 3 years ago #

    That works great, thank you! Have it set up like this:

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

    Another problem i didn't realise before, but my "Newer" / "Older" links don't appear to be working, have them set up like:

    <div class="pagination">

      <li class="older"><?Php previous_posts_link('Older') ?>
      <li class="newer"><?php next_posts_link('Newer') ?>

    </div>

    Any ideas? Thanks so much for your help
    MK

  4. keesiemeijer
    moderator
    Posted 3 years ago #

    try it with this:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( 'posts_per_page=3&author=1&paged='.$paged );
    ?>
  5. David Gwyer
    Member
    Posted 3 years ago #

    Something along the same lines is this, which basically shows posts belonging to administrators (you might have more than one admin).

    <?php

    if (have_posts()) : while (have_posts()) : the_post();

    global $authordata;
    $user = new WP_User( $authordata->ID );

    if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
    if ( in_array('administrator', $user->roles) )
    continue;
    }

    // ...rest of loop code as usual

    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic