Learn how to create page templates, add new pages, change the site's front page, and insert images in WordPress. Gain insights on how to maneuver through the WordPress dashboard and how to use a code editor to make adjustments to your website's pages.
Key Insights
- The blog section of a WordPress site can be refined by creating a page template, and the reserved name for this template is page.php.
- Creating a new page in WordPress can be done through the Dashboard, and the content of the page can be customized using a code editor like single.php.
- To alter the front page of a WordPress website, settings can be adjusted in the Dashboard to display a selected static page by default.
- WordPress allows for the insertion of images to web pages through the 'Add Media' button in the post section of the Dashboard.
- If the image is not displaying as desired, alignment and positioning can be corrected by adjusting the corresponding classes in the CSS file of the theme.
- Additional pages can be added to the website using the 'Add New' button in the Dashboard, with each page's content customized using the code editor and published to the live site.
Dive into the versatile world of WordPress with this detailed tutorial, as it guides you step-by-step through the process of creating page templates, adding new pages, changing your site's front page, and inserting images.
This exercise is excerpted from Noble Desktop’s past WordPress training materials and is compatible with WordPress updates through 2020. To learn current skills in WordPress, check out our WordPress Bootcamp and coding bootcamps in NYC and live online.
Topics Covered in This WordPress Tutorial:
Creating the Page Template, Adding the Title, Adding New Pages, Changing the Site’s Front Page, Inserting Images
Exercise Preview
Exercise Overview
Now that the blog section of the site is done, we can make a page template. Pages in WordPress contain a single post of info, like a normal, simple webpage. Just like single.php, WordPress has a reserved name for the page template, called page.php. If the theme contains a file called page.php, WordPress will automatically use it as the page template.
If You Did Not Do the Previous Exercise
- In a web browser, go to localhost:8888/mrp/wp-admin (Mac) or localhost/mrp/wp-admin (Windows) and log in if prompted.
- On the left of the Dashboard, mouse over Appearance and click Themes.
- Click the Add New button.
- Click the Upload link, then the Browse (or Choose File) button.
- Navigate to Desktop > Class Files > WordPress.org Class and double–click mrpTheme-ready-for-pages.zip to open it.
- Click Install Now, then click Activate.
Making Page.php
We want page.php to be very similar to the single.php page, so it will be best to make a duplicate.
In a code editor, open single.php from the mrpTheme folder, if it isn’t already open.
- Save the file as page.php into the mrpTheme folder located here:
- Mac: Hard Drive > Applications > MAMP > htdocs > mrp > wp-content > themes
- Windows: C: > xampp > htdocs > mrp > wp-content > themes
-
This page doesn’t need all the comments and post info, so delete the
<
h2>
title, time & tags paragraph, and the comments div, leaving only the_content()
in the Loop as shown below:<?php get_header(); ?> <div id="primary"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php endwhile; ?> <?php endif; ?> </div><!—end primary—> <?php get_sidebar(); ?> <?php get_footer(); ?>
-
Above the Loop, we want an
<
h1>
showing the page title. Add the following<
h1>
and function on line 2:<?php get_header(); ?> <h1><?php the_title(); ?></h1> <div id="primary">
Save the file.
- Let’s test these out. Open up a browser and go to:
- Mac: localhost:8888/mrp
- Windows: localhost/mrp
Click the Sample Page link to see the page.php file in action.
Creating New Pages
Now that we have our page template set up, we can make new pages through the Dashboard. Right now, we just have the default Sample Page page that every WordPress install starts with.
- In the browser, go to:
- Mac: localhost:8888/mrp/wp-admin
- Windows: localhost/mrp/wp-admin
Log in if needed.
We want to delete the default page. On the left, click Pages.
Mouse over Sample Page to see its options, then click Trash.
Now we can add our pages. At the top, click Add New.
In the top-right corner of the post section, click the Text tab.
For the title, type: Welcome to MRP
The content we want is in the theme folder. Switch back to your code editor.
Open content-index.html from the mrpTheme folder.
Select all (Cmd–A (Mac) or CTRL–A (Windows)) the code.
Copy it (Cmd–C (Mac) or CTRL–C (Windows)).
Close it.
Switch back to the Add New Page window in the browser.
Paste (Cmd–V (Mac) or CTRL–V (Windows)) the code into the main text area.
Click Publish.
At the top, click Add New.
For the title, enter: Contact
Switch to your code editor.
Open content-contact.html from the mrpTheme folder.
Select all the code.
Copy it.
Close content-contact.html.
Switch back to the Add New Page window in the browser.
In the content section, paste (Cmd–V (Mac) or CTRL–V (Windows)) the code.
Click Publish.
At the top, click Add New.
For the title, type: Latest News
We’re leaving this one blank because the blog will go here, so just click Publish.
Changing the Site’s Front Page
We’d like the front page of the website to show the Welcome to MRP page by default. Right now it shows the posts, which we want on the Latest News page. There’s a setting in the Dashboard that controls this.
On the left, mouse over Settings and click Reading.
-
For Front page displays, check A static page and choose:
Front page: Welcome to MRP Post page: Latest News Click Save Changes.
At the top of the page, click on the Monteith Restoration & Performance title to test out the changes to the site.
Notice that you see the Welcome page first. Click Latest News to see the blog posts. Whoops, the blog page title is wrong.
The blog page is controlled by the index.php file. Switch back to your code editor.
Switch to index.php. (If it isn’t open, open it from the mrpTheme folder.)
-
Replace the static
<
h1>
title (around line 2) with a dynamic PHP title:<?php get_header(); ?> <h1><?php the_title(); ?></h1> <div id="primary">
Save the file.
- Let’s test these out. In the browser, go to:
- Mac: localhost:8888/mrp
- Windows: localhost/mrp
Click Latest News to see the blog posts. Hmm, now the blog page is showing the title of the most recent post. That’s not right—we will need to use a different WordPress function that pulls in the page title.
Switch back to your code editor.
-
Make the following changes to the PHP title (that’s a pair of single quotes inside the parentheses):
<?php get_header(); ?> <h1><?php wp_ title(''); ?></h1> <div id="primary">
NOTE: The wp_title
()
function will work in this case, but by default it will put>>
in front. The (''
) that we’re feeding it says to not put anything in front. Save the file.
- Let’s test these out. In the browser, go to:
- Mac: localhost:8888/mrp
- Windows: localhost/mrp
Click Latest News to see the blog posts. That’s better.
Inserting Images
- Let’s add an image to the Welcome page. In the browser, go to:
- Mac: localhost:8888/mrp/wp-admin
- Windows: localhost/mrp/wp-admin
Log in if asked.
On the left, click Pages.
Click the Welcome to MRP page.
Click the Visual tab.
Click at the beginning of the first heading, About Us.
-
As shown below, click the Add Media button to upload an image.
- In the Upload Files tab, click the Select Files button and navigate to:
- Mac: Hard Drive > Applications > MAMP > htdocs > mrp > wp-content > themes > mrpTheme > img
- Windows: C: > xampp > htdocs > mrp > wp-content > themes > mrpTheme > img
Double–click get-to-know-us.jpg.
After the image appears, on the right next to ALT Text, type: Get to know us
-
Choose the following options for the image:
Alignment: Right Link To: None Size: Full Size Click the Insert into page button.
Click the Update button.
-
At the top, click the Monteith Restoration & Performance title to see the site.
The image is in the heading, but not floating to the right. We set right alignment on the image, so why didn’t it work? When you set align left or right, all WordPress does is apply a class to those images. In this case, it applied the .alignright class. We need to style those classes in our CSS file.
Switch back to your code editor.
Switch to style.css. (If it’s not open, open it from the mrpTheme folder.)
Our static HTML file had classes for this, but they were named imgRight and imgLeft. Locate .imgRight and .imgLeft starting around line 426. They are above the comments and #postsNavLink styles.
Change their names to .alignright and .alignleft to match WordPress’s classes.
Save the file.
- In the browser, reload:
- Mac: localhost:8888/mrp
- Windows: localhost/mrp
Now the image should be properly floated right.
Bonus: Finishing the Rest of the Pages
There are three more pages to add. Their content is stored in HTML files in the mrpTheme folder.
- Open a browser and go to:
- Mac: localhost:8888/mrp/wp-admin
- Windows: localhost/mrp/wp-admin
Log in if asked.
On the left, mouse over Pages and click Add New.
For the title, enter: About Us
Switch to your code editor.
Open content-about.html from the mrpTheme folder.
Select all (Cmd–A (Mac) or CTRL–A (Windows)) of the code.
Copy it (Cmd–C (Mac) or CTRL–C (Windows)).
Close the file.
Switch back to the Dashboard browser window.
In the top-right corner of the post section, click the Text tab.
Click into the main text area and paste (Cmd–V (Mac) or CTRL–V (Windows)) the code in.
Click Publish.
At the top, click Add New.
For the title, enter: Facilities
Switch to your code editor.
Open content-facilities.html from the mrpTheme folder.
Select all (Cmd–A (Mac) or CTRL–A (Windows)) of the code.
Copy it (Cmd–C (Mac) or CTRL–C (Windows)).
Close the file.
Switch back to the Dashboard browser window.
In the content section, paste (Cmd–V (Mac) or CTRL–V (Windows)) the code in.
Click Publish.
At the top, click Add New.
For the title, enter: Services
Switch to your code editor.
Open content-services.html from the mrpTheme folder.
Select all (Cmd–A (Mac) or CTRL–A (Windows)) of the code.
Copy it (Cmd–C (Mac) or CTRL–C (Windows)).
Close the file.
Switch back to the Dashboard browser window.
In the content section, paste (Cmd–V (Mac) or CTRL–V (Windows)) the code in.
Click Publish.
At the top, click the Monteith Restoration & Performance title to see the site.
Click the navbar links to test out all the pages.