0

I am setting up Wordpress site for a client with very limited options for her to edit. As a part of this customized and very limited setup, I have created front-page.php and I am hard-coding the navigation. Options-reading in the Wordpress admin will not be available to her. All is good, except I am lost on how to hard link to the list of posts? I have the Loop set up in index.php.

I know that there is echo get_permalink( get_option( 'page_for_posts' ) );

but the page for posts is not assigned and will not be assigned. When I try that now, the link takes me to the last post individual page.

Thank you for your input!

Clarification: I don't want to create an extra "page" just to display a list of posts. Is there a way to link to index.php, that displays a list of posts without having to create a "page"?

Clarification 2: It seems like a small thing to have an empty (to the client) Blog "page" that sits in the Admin with nothing visibly entered, but I am planning to do this install over and over for multiple clients with the same need, and this empty page should not be the part of the interface.

Contents of index.php

<?php
get_header();
if ( have_posts() ) {
    while ( have_posts() ) {
        the_post(); 
        the_post_thumbnail(); 
    } // end while
} // end if

get_footer(); 
?>
7
  • you've definitely set the Posts Page in admin settings? And this page exists?
    – Dan.
    Nov 27 '16 at 15:32
  • no, the Posts Page is not set in the admin and I prefer not to set it at all. I have index.php to display the list of all posts. I should be able to get to it by using a variable in the URL, no?
    – Natalia
    Nov 27 '16 at 15:34
  • I'm afraid not, see my answer.
    – Dan.
    Nov 27 '16 at 15:48
  • If the reason you don't want to use the Posts Page setting/feature is because you don't want your client to be able to edit it, then you can just set it and then remove access to that settings page.
    – Dan.
    Nov 27 '16 at 15:55
  • sorry I think I misunderstood. As it is at the moment, you are successfully displaying list of posts, and that page is using index.php, but you just need to link to it? In that case, you can use home_url('/slug'). If you want to create the link without hardcoding anything whatsoever, though, you will need it to be coming from a setting in admin.
    – Dan.
    Nov 27 '16 at 16:12
0

You will need to create another page, in admin, if you want the home page and the posts page to be different pages (have different URLs).

Or, if you want to display the posts on the same page as the other page in question, then still keep reading...

If you want to use index.php to show posts, but not use the Posts Page setting, then you'll need to write a custom query in index.php.

You can use WP_Query, or get_posts() or other methods.

Example using WP_Query:

$args = array(
    'post_type' => 'post'
    'posts_per_page' => -1
);    

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        the_title();
        the_post_thumbnail();
    }
    /* Restore original Post Data */
    wp_reset_postdata();
} else {
    // no posts found
}

If you want to have the posts on a different URL, then it's gonna have to be a separate page. If you don't want it to be 'empty' then put a shortcode in there (to display posts), rather than use the Posts Page setting.

You could create a shortcode and put a WP_Query in it.

2
  • You're right in your EDIT -- the Blog Posts page won't use front-page.php. Per the Template Hierarchy, it'll use home.php, and if home.php doesn't exist, it'll use index.php.
    – Pat J
    Nov 27 '16 at 16:19
  • Yep you're right :). Deleting answer though as OP's question was about something else
    – Dan.
    Nov 27 '16 at 16:31

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.