-1

I want to show all posts on one page (The post image, post title, post metadata, post description of 3 lines with "read more" link). I have created a custom page and assigned it in the settings for displaying posts. For now, the page is showing all data for every post on the page. I have selected "For each article in a feed, show" to "summery" in "settings>Reading" section in the WordPress. Can anyone please help out?

0

You'll need to create or edit a template in order to display all posts in a particular way. The settings you have adjusted aren't enough instructions to WordPress on what to display where, and the Feed setting only adjusts the RSS feed - not the actual visitor-facing URLs.

First: create a child theme if you don't already have one. This way when your parent theme is updated, you won't lose your changes.

Next: decide whether you really want all posts to appear on a certain Page (i.e. at http://example.com/all-posts/) or if you would rather have them appear on your homepage (i.e. http://example.com/). The homepage by default already queries the Posts on your site, so unless you need different functionality on your homepage, this would be the recommended place to display all the Posts. That way you're just slightly modifying the database query - instead of "get 5 Posts" you'll be saying "get all Posts" - whereas on a Page, you would be saying "get all Posts" instead of "get this one Page".

Then: in your child theme, create either front-page.php for the homepage or tpl-all-posts.php for any Page of your choosing. This is the file that will control the output of whichever particular URL you are wanting to show all the posts on. Inside the file, you may want to start by copying the parent theme's index.php which contains the simplest Loop possible.

Then, to tell that page you want all Posts and not just a limited set, you will want to create a functions.php file in your child theme. If you chose the homepage, you can add this:

// use the Pre Get Posts hook that modifies the main database query
add_action('pre_get_posts', 'wpse_modify_query');
function wpse_modify_query($query) {
    // Replace the main query on the homepage
    if($query->is_main_query() && !is_admin() && $query->is_home()) {
        // Setting posts per page to -1 gets them all
        $query->set('posts_per_page', '-1');
    }
}

Or, if you chose a Page, change the conditional:

// use the Pre Get Posts hook that modifies the main database query
add_action('pre_get_posts', 'wpse_modify_query');
function wpse_modify_query($query) {
    // Replace the main query on the homepage
    // Change the last part ('all-posts') to whatever your Page's slug is
    if($query->is_main_query() && !is_admin() && $query->is_page('all-posts')) {
        // Setting posts per page to -1 gets them all
        $query->set('posts_per_page', '-1');
    }
}

That will give you all Posts on whichever page you chose. Then, in your template file, you can adjust the Loop. You may want to use the_excerpt() instead of the_content() which will pull just part of the post content and will add the Read More link you're needing. If the excerpt length isn't to your liking there are filters to change its length, and filters to change the Read More link if you want to make it more screen reader friendly.

From there, you can call get_post_meta() to get the postmeta and then you'll need to determine how you want to display it, what HTML to include, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.