Forums

Displaying "by <author>" next to list of recent posts (20 posts)

  1. stoo31
    Member
    Posted 3 years ago #

    I have a list of the most recent posts in my sidebar as such:

    <?php wp_get_archives('type=postbypost&limit=10'(); ?>'); ?>

    This has been working fine to display the most recent 10 posts, but I wish to display "by admin" or whoever the author is next to it.

    When I put the standard php author code in it doesn't display and was wondering if there is a solution to this?

    Thanks

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    Might have to resort to something like this instead:

    <?php
    $posts=get_posts('showposts=10');
    if ($posts) {
    foreach($posts as $post) {
    setup_postdata($post);
    ?>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?> by <?php the_author() ?></small>
    <?php }
    }
    ?>
  3. stoo31
    Member
    Posted 3 years ago #

    Thanks Michael

    That worked a treat!

  4. stoo31
    Member
    Posted 3 years ago #

    This is actually causing a problem on my blog, it for some reason only displays the most recent post on the "single-post" page?

    I'm not sure what a solution for that would be?

  5. MichaelH
    Volunteer
    Posted 3 years ago #

    Guessing you have a Conditional Tags test, where you put that code, that is causing that.

    I used the WordPress Default theme and in wp-content/themes/default/sidebar.php I put that code just before:
    <?php wp_list_pages('title_li=<h2>Pages</h2>' ); ?>

  6. stoo31
    Member
    Posted 3 years ago #

    Hmm, I can't see any conditional tags in the sidebar or on the main index.

    Do you have any idea what I need to do to rectify it as I can't see anything obvious!

    Thanks again

  7. MichaelH
    Volunteer
    Posted 3 years ago #

    Link to download theme you are using?

  8. stoo31
    Member
    Posted 3 years ago #

  9. stoo31
    Member
    Posted 3 years ago #

    Hi again,

    Don't mean to bug you, I'm just eager to get this sorted!

    Thanks again for your help.

  10. MichaelH
    Volunteer
    Posted 3 years ago #

    Not seeing the problem on main page, single post pages, category/date archive pages, or Pages.

    Download a new version of that theme if necessary.

    I put the code above in sidebar.php just before:
    <?php wp_list_pages('title_li=<h2>Pages</h2>' ); ?>

  11. stoo31
    Member
    Posted 3 years ago #

    This is very confusing, I've just reinstalled a fresh download of the theme.

    I've immediately inserted the code just where you stated and I get the same error.

    It will only display the most recent post instead of the post that has been clicked on.

  12. MichaelH
    Volunteer
    Posted 3 years ago #

    Plugins?

  13. stoo31
    Member
    Posted 3 years ago #

    I disabled them all had the same issue.

    I probably should have posted you a link before but it's not active yet I am just finalising it.

    but you can have a look here

    It's probably something I have done, but it's not standing out to me.

    Thanks again for all your help, much appreciated!

  14. MichaelH
    Volunteer
    Posted 3 years ago #

    Don't quite understand what's happening but here your contact page directs to http://www.dpadmagazine.com/contact/ and in page source I see reference to wp-content/themes/arthemi

  15. stoo31
    Member
    Posted 3 years ago #

    The header is taken off the main site, with the menu corresponding to elements of that.

    It shouldn't however effect the workings of the blog as the menu has been hand coded to link back to the main site.

  16. MichaelH
    Volunteer
    Posted 3 years ago #

    What am I missing?

    This links show the recent posts:
    http://www.blog.dpadmagazine.com/
    http://www.blog.dpadmagazine.com/2009/02/09/bioshock/
    http://www.blog.dpadmagazine.com/author/admin/

    Your nav bar (e.g. like Subscribe) direct you NOT to your WordPress blog, but to http://www.dpadmagazine.com/ and that is evidently another blog that uses a different theme.

  17. stoo31
    Member
    Posted 3 years ago #

    I don't think I am explaining myself very well sorry.

    If you click the second post in the sidebar (http://www.blog.dpadmagazine.com/2009/02/08/tester-tester-tester/) which you will notice displays the correct URL & header but doesn't display the content of the relevant post it only displays the most recent post.

    When I take the sidebar code out that you gave me it returns to normal.

  18. MichaelH
    Volunteer
    Posted 3 years ago #

    Maybe something with your single.php or your permalinks or even .htaccess, because if you visit http://www.blog.dpadmagazine.com/author/admin/ and click on that test post you see the same problem.

  19. stoo31
    Member
    Posted 3 years ago #

    The blog functions fine when I take the sidebar code that you gave me out though. So it is something in that sidebar code on it's own or it is conflicting with some code in my theme, but I can't locate anything that would be causing it.

  20. MichaelH
    Volunteer
    Posted 3 years ago #

    This, in a widget from Otto's PHP Code Widget, or in a sidebar.php works:

    <?php
       $args=array(
       'showposts'=>5,
       'caller_get_posts'=>1
       );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> by:  <?php the_author(); ?></p>
    
    <?php
    endwhile;
    }
    ?>

    Note: have also used the Recent Posts plugin/widget recently that allows configuration of things like this via Settings ;)
    http://rmarsh.com/plugins/recent-posts/

Topic Closed

This topic has been closed to new replies.

About this Topic