• Resolved spiderlinginc

    (@spiderlinginc)


    I would like to have it so that only the latest post from one author is displayed on the main page.

    I tried CQS, but not exactly what I need. I also tried WP-Sticky and 1 post per page which keeps the post at the top, but still not exactly what I want.

    Is there a plug-in or some custom coding that could be done to achieve this?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • miloandrew

    (@miloandrew)

    you can do it a few ways.

    First is probably just to have a custom index.php.

    Most usually have something like this:

    <?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    <!-- do some stuff for post formatting, comments, etc -->
    
    		<?php endwhile; ?>
    
    <?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.
    
    	<?php endif; ?>

    what you need to do to take out the “while” loop. So change to something like:

    <?php if (have_posts()) : ?>
    
    	<?php the_post(); ?>
    
    <!-- do some stuff for post formatting, comments, etc -->
    
    <?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.
    
    	<?php endif; ?>

    That should basically make only 1 post on the front page.

    Another way to do it is to do something in a custom loop outside of the main loop – something like this:

    <?php $my_query = new WP_Query('showposts=1'); ?>
    
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <!-- Do your formatting... -->
    <?php endwhile; ?>

    Either way would work.

    miloandrew

    (@miloandrew)

    You can get more info on custom loops here:

    https://codex.www.ads-software.com/The_Loop

    Thread Starter spiderlinginc

    (@spiderlinginc)

    Thanks miloandrew for the info.

    This helps in getting the single post, but not for one specific author. So, following the Loop link you provided and a subsequent link or two from there I found the https://codex.www.ads-software.com/Author_Templates. I tried the $curauth->ID variable, but got a blank page. I then opened the author-template.php file and found $authordata->ID and successfully used it with the code below.

    <?php if (have_posts()) : ?>
     <?php while (have_posts()) : the_post();  if ($authordata->ID == '2') : ?>
     <!-- Formatting -->
    
       <?php break; ?>
      <?php endif; ?>
     <?php endwhile; ?>
    
     <?php else : ?>
    
    <H2 class="center">Not Found</H2>
    <P class="center">Sorry, but you are looking for something that isn't here.</P>
    
     <?php endif; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘single post by author’ is closed to new replies.