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

Managing full posts

From: Dreamweaver and WordPress: Building Sites

Video: Managing full posts

With its default settings, WordPress shows the most recent ten posts on the homepage. If you take a look at the archives link, you will see a listing of up to ten archives. The same thing is true of search results. While it's great to have a configurable setting, showing how many posts and archives and search results you can show, I think it's a little bit of a limitation that the same setting applies across the board. In this movie, we are going to look at how you can limit the number of posts displayed on the home page without affecting the rest of your site.

Managing full posts

With its default settings, WordPress shows the most recent ten posts on the homepage. If you take a look at the archives link, you will see a listing of up to ten archives. The same thing is true of search results. While it's great to have a configurable setting, showing how many posts and archives and search results you can show, I think it's a little bit of a limitation that the same setting applies across the board. In this movie, we are going to look at how you can limit the number of posts displayed on the home page without affecting the rest of your site.

So I'm going to drill into my theme, tpa, and open up the index.php file, which is the main content area, switch to Code view, and I wanted to take just a moment to show you the PHP code that's responsible for outputting those posts. It starts here with the code block on line 4 and continues all the way down to line 23, the endif that you find there. This is known in WordPress speak as the loop. If there are posts, while there are posts, output the content that's found, in this case, in an article tag, including a link to title and an h2 tag, a div of meta content--basically the time it was published--the content itself, and then another div of post metadata, which show tags, categories, and comments.

By default, this loop will display as many posts, up to the number available defined in the WordPress settings. Let me show you where that is. So go to Settings > Reading, and here you'll see blog pages that show at most ten posts. So if we take a look at the site now, if I click on Visit Site, there is one post, there is two posts, and you have just two there. But let's go ahead and search for IP, and here's one, two, three. So it definitely shows more than two and if I had ten results for that, it will show those.

Now, let's look what happens if I change it to 1. Save Changes. Now let's go back to our site, and here we have just the one post on the homepage. That's great. But now, let's search for IP again, and we only have one search result returning. So the value that you set here is really a global setting. I'm going to restore it to 10 and then click Save Changes. Now, let's go back to Dreamweaver where we can put in a little bit of PHP code to limit your posts just on the homepage. And this code will go right after if (have_posts() ) on line 4.

I am going to open up another PHP code block, and put in the function query_posts(); and then within the parentheses, a pair of quotes, and we put in the property showposts= and then the number of posts that you want shown, in this case 1. Now let me close off the PHP function, save this. With the file saved, let's go back and take a look now.

In our site, we now have just the most recent posts, and in our search results, I will search for the same two-letter combination, and now we've got multiple results there. You will find that the query_posts function is very helpful. You can actually use it to limit your post to a specific category or tag, as well as the number. However, you should be aware that because it alters the main loop, it could affect the rest of your page.

To avoid these issues, use the wp_reset_query function after you're done. This code will go after the endif. Let me scroll up a little bit so you can see it better. Another code block, wp_reset_query, and then just an open and close parenthesis and a semicolon. Close the code block, and this page is done. So let me save it. Let's try it out in Dreamweaver.

I'll open up the index.php page from the site root, go into Design view and then Live view, and now I should have just the single post here on the homepage. It looks good. Let's try our search, and I'll enter in a value and then hold down the Ctrl key while I click Search. So I get the search results that follow that link, and here's our multiple search results. Okay. So we have successfully limited our index page to showing just the most recent posts while displaying multiple entries on other WordPress pages throughout the site.

Now that you've got a handle on managing full posts, you are ready to tackle partial posts, or excerpts.

Show transcript

This video is part of

Image for Dreamweaver and WordPress: Building Sites
Dreamweaver and WordPress: Building Sites

21 video lessons · 16455 viewers

Joseph Lowery
Author

 

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.

Join now "Already a member? Log in

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 Dreamweaver and WordPress: Building Sites.

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.