Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Single-post navigation

From: WordPress: Building Themes from Scratch Using Underscores

Video: Single-post navigation

Now that were done styling all the content that can Here again we have one of these php functions that does a As part of that html, you get this next and previous links that are displayed.

Single-post navigation

Now that were done styling all the content that can appear within the content section of our single post page. We scroll down and see that there's one more item that looks really off from the rest. It's this post navigation. You see in most WordPress themes you have post navigation. That allows you to navigate to the previously published post, or the next published post when you're on a single post, and it displays down here. Right now it looks completely off from the rest of my design. If I look at my actual design, you'll see here I have a line and then it says, Previous Post and Next Post.

With the titles of the post nicely bolded, and then there's another line. So this clearly separates the navigation from the rest of the content. But if I look at the existing navigation, you see instead of, previous and next, we just have an arrow. And the font is all wrong and it's not really separated. So here I need to do some work to make the navigation match my design. If you remember back to when we started working with a single post template, you may remember that inside the loop, I said we have first get template part that targets content-singledoc.php.

And then we have a couple of the functions including the post navigation. So here we have the function that creates the post navigation, and now we can use Netbeans to navigate directly to that function, by holding down ctrl or cmd, and clicking on the function name. And this takes us to the function that displays next or previous post. Here again we have one of these php functions that does a bunch of work for us where we only need to change the output. So this function goes and finds the previous and next posts and places them into variables, called previous and next, and then it displays some html.

As part of that html, you get this next and previous links that are displayed. And this is what we actually want to change. 'because if you look closely here, you see this is the divider that is wrapped inside, and within here, we have a span, that has the arrow. So this is the left arrow, and here you have the right arrow. And then it says, Next post link, and Previous post link. What I want to do now is create a new set of markup. So instead of displaying this single line with the arrows, I'm going to display two lines, and I'm going to have the top part be just the divider.

I want the actual post title to be an h1 heading. And I can do that simply by changing the markup within the previous post link and the next post link functions. If you go to the code snippets for this movie I've prepared that markup for you. So here I'm just going to copy it out. Go back into Netbeans, and just replace these two functions with my code. And if you look closely you'll see that this is pretty much the same. The only thing I've changed is, I've added new markups. So here we have div, it also has the class nav previous, and within that div we have another div called nav indicator.

The nav indicator is where is says, previous post and next post. And then, in addition, we have an h1 that displays the link, so that would be the actual link to the previous or next post including the title. Now I can save this first edit. And go back to my browser, and see if the output is correct, and it is. Here we have the previous post, and next post texts, and we see that the styling from underscores already separates them left and right. And I also see that my titles are nice and bolded.

And I don't really have to do anything else with that. Now i need to apply some extra styling to make this actually look the way it does in the design. So I'm going to go to my code snippets again and copy out this set of styles here. And here you'll see that the style rules that I'm copying out actually apply to more than just the post-navigation. I'll explain why in a second. So I'll copy out all of these style rules, go back into Netbeans and openstyle.css. And here I'm going to search for comments, navigation, and here you see we already have predefined styles.

And these styles apply to site main comment navigation, paging navigation, and post navigation. All three of them. And what's happening here is there's several different places where navigation can appear. So what I want to do is make sure that all of these navigation items on all the different pages have the same overall look. So I'm going to remove these three styles, and replace them with the ones I created. And then we can take a quick look at them. And you see all I'm doing here is setting the same font size, and font family, and font color for all the navigation on my entire site.

So, I'm not actually saying anything about the borders or margins or anything like that. I'm simply changing the positioning and changing the font families, so that all my navigation will now look exactly the same. Finally, I'm setting the font weight for the h1 tag, so that would be the actual post title, to 900, which is the heaviest font weight. Now I can save my styles and go and reload my page again, and you'll see the styles have changed ever so slightly, and my content has now shifted in under the rest of the content.

So now we have proper alignment. But now you see a bit of a problem, and that is, right now, the navigation doesn't actually work. If you tried to click on it, you can see nothing happens. And that's because, the content has been covered by the comments. And that's because of how we're aligning it. We're using a float left and float right, and these containers are not clearing properly. I also see that this still doesn't match my design exactly. You'll remember that in the design, there's a line at the top and a line at the bottom. So here, I need to add some more wrappers around my content and then add additional styles to make everything match exactly.

So I'll go back to my code snippets, and scroll down. Here you'll see I have some alternate code for the template tags function. So here I'll copy out the code. And go to template tags, and I'll replace the entire nav tag here. The only thing that's different about this new code is that I've added this divider that says, Post Nav Box, and it clears so that it pushes any other content further down. The reason why I wanted you to copy out all of it, is so that you don't accidentally make a mistake or put the divider in the wrong place.

It's just easier to copy the whole thing. So, now that I've added this additional divider with a new class, I also need to add an appropriate style to go with the class. And it's this divider I'm going to use to add a border at the top, and border at the bottom. I'll go back to style, and then right down here underneath nav previous h1, I'm going to add a final CSS rule. And it's this one that targets post navbox. So, I'll copy that one, and paste it in. And you see, this style adds padding on the top and the bottom.

It adds a margin on the bottom of 4em's to push the comments really far down. And then it adds a border on the top, and a border on the bottom. So when I now save my style, the style will target this new divider that I added around my navigation. And I'm going to reload my browser one more time here. You will see now the navigation looks exactly like it does in my design, and I can now click on the links again. And since my navigation is styled to fit within the framework of the rest of the site, and I'm using the existing classes that were already there.

This is now also fully responsive. So when I resize my window here, you will see that just like with everything else, the post navigation is fully responsive. And changes depending on the width of the window.

Show transcript

This video is part of

Expand all | Collapse all
  1. 10m 55s
    1. Welcome
      1m 4s
    2. What to know before you start this course
      2m 40s
    3. How this course and the lesson files work
      3m 12s
    4. Introducing Simone: A preview of the final project
      3m 59s
  2. 21m 28s
    1. Installing and running WordPress on your computer
      3m 53s
    2. Getting and installing Underscores
      4m 11s
    3. Installing WordPress Theme Unit Test data
      4m 18s
    4. Installing the Developer plugin
      2m 58s
    5. Installing and setting up NetBeans or another IDE
      6m 8s
  3. 16m 15s
    1. Designing for mobile, content, and style
      4m 52s
    2. How do WordPress themes work?
      4m 48s
    3. Understanding the WordPress template hierarchy
      2m 19s
    4. Underscores: An overview
      4m 16s
  4. 37m 5s
    1. Setting up style.css
      4m 47s
    2. Configuring baseline settings and functions
      6m 6s
    3. Enabling custom fonts and font icons
      5m 44s
    4. Applying global styles
      5m 11s
    5. Styling basic layout components
      6m 19s
    6. Making the site layout responsive
      8m 58s
  5. 23m 18s
    1. Styling the default header
      6m 25s
    2. Hiding the site title and tagline
      5m 32s
    3. Adding an optional header image function
      5m 23s
    4. Placing the header image behind the site title
      5m 58s
  6. 40m 55s
    1. Setting up menus
      3m 12s
    2. Styling the menu
      7m 42s
    3. Using Superfish for accessible menus
      8m 0s
    4. Making the menu responsive
      7m 3s
    5. Creating a custom social media menu
      5m 51s
    6. Styling the menu with icons from Font Awesome
      9m 7s
  7. 18m 9s
    1. Adding the search form
      6m 27s
    2. Adding the search icon
      6m 55s
    3. Adding show/hide functionality to the search form with jQuery
      4m 47s
  8. 33m 20s
    1. Adding a widgetized area to the footer
      7m 10s
    2. Using the Monster widget plugin to test all widgets
      2m 11s
    3. Styling the footer
      3m 6s
    4. General widget styling
      5m 33s
    5. Adding custom styles to specific widgets
      7m 34s
    6. Using Masonry to make footer widgets responsive
      7m 46s
  9. 54m 49s
    1. Changing the Single Post Template content structure
      5m 54s
    2. Changing the output of meta elements
      7m 2s
    3. Styling the Single Post Template
      7m 57s
    4. Making post meta responsive
      6m 21s
    5. Styling blockquotes
      5m 39s
    6. Creating pull quotes and pull images
      5m 1s
    7. Working with image captions
      4m 27s
    8. Working with image galleries
      4m 57s
    9. Single-post navigation
      7m 31s
  10. 30m 23s
    1. Working with the comments template
      8m 42s
    2. Using Gravatars in comments
      2m 42s
    3. Styling comments
      7m 26s
    4. Highlighting post author comments
      3m 36s
    5. Styling the comment form and messages
      7m 57s
  11. 18m 43s
    1. How do featured images (post thumbnails) work?
      2m 57s
    2. Defining featured image sizes
      3m 30s
    3. Generating new featured images with a plugin
      1m 46s
    4. Adding featured images to a template
      5m 7s
    5. Styling the featured image
      5m 23s
  12. 1h 2m
    1. The index template hierarchy
      2m 21s
    2. Customizing and styling index templates
      10m 10s
    3. Displaying excerpts or full content on index pages
      3m 6s
    4. Adding a custom Read More link
      3m 48s
    5. Adding featured images
      4m 0s
    6. Creating custom pagination navigation
      6m 4s
    7. Highlighting Sticky Posts
      2m 55s
    8. Creating custom post format templates
      5m 30s
    9. Highlighting the most recent post in the index template
      7m 22s
    10. Embracing modular design
      2m 29s
    11. Working with archive.php
      5m 54s
    12. Customizing the search results and the 404 template
      8m 28s
  13. 9m 7s
    1. Styling pages
      3m 4s
    2. Creating custom page templates
      6m 3s
  14. 4m 30s
    1. Adding editor styles to match front-end styles
      4m 30s
  15. 2m 20s
    1. Further learning
      2m 20s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed WordPress: Building Themes from Scratch Using Underscores.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.