Roots Discourse

Best practice for adding new page

(This is my first time using Sage, so please bear with me.)

I have a site with a navigation menu. It has links created through the custom links (Services, Solutions, Careers, etc.) on Wordpress, so I can type any URL.

My question is: what is the best practice for adding these different pages?

Right now, I’m controlling the layout of my front page with a front-page.blade.php file.

Should I create another file like this in the /views directory for each section (Services, Solutions, Careers, etc.) and create a file in the /partials directory to start building the page for each section?

If so, what would be the URL location that I type in on Wordpress’s nav menu?

For example:

If the file in views is called something like services.blade.php, and the file in partials is called services-banner.blade.php, would the URL in the nav menu be simply /services?

Thank you and my apologies for such a novice question. I’ve tried searching for an answer but it isn’t clear, probably because it’s a very basic question.

I’m not sure I understand your question, but the names of templates in Sage do not determine URLs. If you’re using WordPress’s built-in Menus feature, you shouldn’t need to type in URLs at all: You can simply select the pages you want to appear on the menu, and it will automatically output the correct URLs. The official documentation explains a bit more: https://developer.wordpress.org/themes/functionality/navigation-menus/

In general best practice is not to hardcode URLs anywhere you can avoid it: They’re too easy to change. If you want the URL for an item in WordPress, the best way to get it is to get the ID for that item, and then pass it to a function like get_permalink() which will return a URL for you.

Hi @alwaysblank

Thanks for the reply.

I’d like each page to have its own design, that’s why I don’t want to simply create a Wordpress page or link it as a Wordpress page.

To elaborate a bit more, you can obviously create pages and posts on Wordpress. But if you create them, you modify the page and/or post file to adjust the design and layout, right? At least this is my understanding, but being new to this, I could be wrong.

I thought creating individual pages (as opposed to simply adding a new page on Wordpress’s administration area) allowed me to design each page differently.

I’m sorry if it’s still not completely clear. I will go back to researching this and see if I can find a way to better describe my issue.

Thanks again

WordPress allows you to select templates to apply to Pages (as well as other post types in modern version of WP), which is probably what you want: https://developer.wordpress.org/themes/template-files-section/page-template-files/ You can select these on your page in WordPress, and it will use that template. Sage includes an example: https://github.com/roots/sage/blob/master/resources/views/template-custom.blade.php

IMO this is generally better than trying to create a template that WordPress will try and match to a page based on the slug or ID (which is also possible, but I wouldn’t recommend it) because it is significantly less fragile.

Perfect! That’s exactly what I was after.

Thank you!