Custom home page and blog page

Asked

Viewed 36 times

0

Hello I stayed a long time without getting involved with WP projects

Now I’ve had to take back one and a half. I have the following scenario: the site has the main objective to be an e-commerce (Woocommerce) and secondary a blog. I coded the initial page to show products and below, list the last 4 posts. But I wanted to be able to create a "see all posts" link that takes the user to "/blog" where lists all posts (what would be an initial wordpress blog page). It turns out I’ve tried numerous combinations index.php, home.php, front-page.php (things I know are from the template hierarchy) and I can’t. Someone can give me a light?

I remember in the past, using front-page.php for a custom page that I coded and home.php for the index blog. But it’s not working.

I would not like to use additional plugins. And I would like to remain in the code without many settings in the panel(client rules).

Every day that passes is more difficult to find advanced information on wordpress on google due to semantic disputes with tutorials for beginners.

1 answer

0

The template front-page.php is used to display a static home page, which applies in your "initial page to show products and below, list the last 4 posts".

The template home.php is what will display the blog posts.

And the template index.php is the one that will be displayed if no template fits the user request.

From what I understand, your problem is with the link '"see all posts" that takes the user to "/blog"', right?

For this to work, you need:

  1. Have a template front-page.php with the custom page you want and a template home.php or index.php with the blog posts page.

  2. In Configurações -> Leitura in Wordpress admin panel, mark the following options:

    Your home page displays: A static page (select below)

    Home page: choose one to be your home page

    Posts page: choose one to be your blog page. Remember to choose blog as Slug of this page so that it can be accessed through the /blog address.

  3. On the 'See all posts' link you can write directly /blog on href, but this is a bit risky if the site administrator changes the Slug of the blog page created in the previous step. So the best scenario is to use the function get_post_type_archive_link( 'post' ) to generate the blog page URL dynamically, user-proof.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.