Skip to main content
added 282 characters in body
Source Link
Dan.
  • 856
  • 1
  • 7
  • 10

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.

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
}

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.

added 56 characters in body
Source Link
Dan.
  • 856
  • 1
  • 7
  • 10

Your code - get_option( 'page_for_posts' ) gets the URL of the page that you have setYou will need to be the Posts Pagecreate another page, in admin settings. If you don't set it, then get_option( 'page_for_posts' ) will not return whatif you want itthe home page and the posts page to be different pages (even in this day and age, code is not psychic, or not PHP anywayhave different URLs).

You should create a page for yourOr, if you want to display the posts on the same page as the other page in question, ethen still keep reading.g. call it 'Blog' and set this page to be the Posts Page.

Creating a new page in admin panel doesn't mean thatIf you can't stillwant to use front-pageindex.php for that page. Seeto show posts, but not use the Posts Page setting, then you'll need to write a custom query in template hierarchyindex.php in the docs - https://developer.wordpress.org/themes/basics/template-hierarchy/

EDIT:.

I'm not sure that youYou can use front-page.phpWP_Query for your Posts Page, actually. You may have to create another template fileor 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
}

Your code - get_option( 'page_for_posts' ) gets the URL of the page that you have set to be the Posts Page, in admin settings. If you don't set it, then get_option( 'page_for_posts' ) will not return what you want it to (even in this day and age, code is not psychic, or not PHP anyway).

You should create a page for your posts, e.g. call it 'Blog' and set this page to be the Posts Page.

Creating a new page in admin panel doesn't mean that you can't still use front-page.php for that page. See template hierarchy in the docs - https://developer.wordpress.org/themes/basics/template-hierarchy/

EDIT:

I'm not sure that you can use front-page.php for your Posts Page, actually. You may have to create another template file.

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
}
added 136 characters in body
Source Link
Dan.
  • 856
  • 1
  • 7
  • 10

Your code - get_option( 'page_for_posts' ) gets the URL of the page that you have set to be the Posts Page, in admin settings. If you don't set it, then get_option( 'page_for_posts' ) will not return what you want it to (even in this day and age, code is not psychic, or not PHP anyway).

You should create a page for your posts, e.g. call it 'Blog' and set this page to be the Posts Page.

Creating a new page in admin panel doesn't mean that you can't still use front-page.php for that page. See template hierarchy in the docs - https://developer.wordpress.org/themes/basics/template-hierarchy/

EDIT:

I'm not sure that you can use front-page.php for your Posts Page, actually. You may have to create another template file.

Your code - get_option( 'page_for_posts' ) gets the URL of the page that you have set to be the Posts Page, in admin settings. If you don't set it, then get_option( 'page_for_posts' ) will not return what you want it to (even in this day and age, code is not psychic, or not PHP anyway).

You should create a page for your posts, e.g. call it 'Blog' and set this page to be the Posts Page.

Creating a new page in admin panel doesn't mean that you can't still use front-page.php for that page. See template hierarchy in the docs - https://developer.wordpress.org/themes/basics/template-hierarchy/

Your code - get_option( 'page_for_posts' ) gets the URL of the page that you have set to be the Posts Page, in admin settings. If you don't set it, then get_option( 'page_for_posts' ) will not return what you want it to (even in this day and age, code is not psychic, or not PHP anyway).

You should create a page for your posts, e.g. call it 'Blog' and set this page to be the Posts Page.

Creating a new page in admin panel doesn't mean that you can't still use front-page.php for that page. See template hierarchy in the docs - https://developer.wordpress.org/themes/basics/template-hierarchy/

EDIT:

I'm not sure that you can use front-page.php for your Posts Page, actually. You may have to create another template file.

Source Link
Dan.
  • 856
  • 1
  • 7
  • 10
Loading