Forums

[resolved] Use Loop from Homepage on another Page (7 posts)

  1. PG73
    Member
    Posted 2 years ago #

    Hi

    Hope someone can help, been searching for ages for a solution but can't find one.

    Can the 'Reading Settings' that control how the latest posts are displayed on the homepage (index.php) be used on another page? I've duplicated and renamed the index.php file and made a new page to use that template file, but it doesn't show all the posts as the homepage does, it only attempts to show one, which is just the page's title.

    So is there a way I can add a query string or something to the renamed index.php file to get it to use the same settings? I will need to customise this after as I want it to list the posts by number of comments rather than by most recent, but I think I'll be able to do this once I can at least get it to show all the posts as on the homepage.

    Hope that lot made sense!

    Really appreciate any help you can give me.
    Thanks.

  2. vtxyzzy
    Member
    Posted 2 years ago #

    This is untested, but should be close:

    $posts_per_page = get_query_var('posts_per_page');
    $paged = intval(get_query_var('paged'));
    $paged = ($paged) ? $paged : 1;
    $args = array(
       'posts_per_page' => $posts_per_page,
       'paged' => $paged,
       'orderby' => 'comment_count',
       'order' => 'DESC',
    );
    query_posts($args);
    if (have_posts()) : while (have_posts()) : the_post() {
       // Rest of Loop
    }
    endwhile; endif;
  3. PG73
    Member
    Posted 2 years ago #

    That worked a treat, a big thank you - I really appreciate the help, it was really stressing me out! One last thing (if you don't mind), I was searching and trying for ages to achieve something, that with your help, has been achieved another way. But out of interest, if you could have a quick look at this earlier post I made and let me know if it's possible, thank you.

  4. vtxyzzy
    Member
    Posted 2 years ago #

    No link to other post! ;(

    Please mark this topic 'Resolved'. Thanks.

  5. PG73
    Member
    Posted 2 years ago #

  6. vtxyzzy
    Member
    Posted 2 years ago #

    I took a look at your other post, and that question is beyond my expertise. I did not respond to that post because persons looking at the forum generally look for unanswered posts to see what needs to be addressed.

  7. PG73
    Member
    Posted 2 years ago #

    No problem, thanks for your time and help.

Topic Closed

This topic has been closed to new replies.

About this Topic