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

Changing the appearance of category index pages

From: WordPress 3: Building Child Themes

Video: Changing the appearance of category index pages

WordPress has multiple different index templates that kick in when different indexes are called, the most notable-- and the ones you should see in pretty much every WordPress theme--are index.php, category.php, tag.php, and archive.php. The names are self-explanatory. Sometimes you want different index pages to appear differently in your sites. I often find that while on the main index page it makes sense to have longer versions of the posts, with images and full text, on category and archive index pages it makes more sense to have shorter versions and maybe no images.

Changing the appearance of category index pages

WordPress has multiple different index templates that kick in when different indexes are called, the most notable-- and the ones you should see in pretty much every WordPress theme--are index.php, category.php, tag.php, and archive.php. The names are self-explanatory. Sometimes you want different index pages to appear differently in your sites. I often find that while on the main index page it makes sense to have longer versions of the posts, with images and full text, on category and archive index pages it makes more sense to have shorter versions and maybe no images.

This can be accommodated by calling for an excerpt instead of the content of a post when the category or archive templates are used. If you look at the site the way it is now, you can see that on the front page, or the main index page, we have the full post, web images, and if there's a featured image, the featured image appears at the top. If we go to the category archive page, we'll see the exact same thing. Here we have the full post with images, and if there is a featured image, it's featured at the top. What I want to do is make the content of a post into just an excerpt, and I also take want to take away the featured image.

In a previous movie we looked closely at index.php template. Now we are going to look out the category.php template instead, to find out what we need to change to make the content into just an excerpt. So I'll open the category template and take a look at content within the category template. And here you see, just like with the index template, that we have a loop. It looks for all the posts and then displays each post using that same template file, content.php. So because we want to change the content from a full content into the excerpt, we have to change that in content.php.

I've already made changes to content.php in my child theme already, so I'll keep making changes to the same file in my child theme. I'll open it in my code editor and then I do find where I should make the changes. When I scroll down here, you'll see that under all the header information I have the section here. It starts with is_search and then it shows the_excerpt, if this is_search page, and otherwise it shows the_content. What you're seeing here is that we already have a conditional statement, this if statement, that tests whether or not this is a search archive, and then it displays the excerpt.

So what I need to do is add some conditions to the conditional statement so that we can test for more than just a search archive. Fortunately for us, just like pretty much everything else in WordPress, this has already been kind of taken care of for us. There are conditional tags available that can test for all the things that we want to test for. There is a conditional tag for Category Pages. It's simply is_category. There's also one for Tag Pages, is_tag. There is one for Archive Pages, is_archive, and so on. I think you see the pattern here.

So what we need to do is add these conditionals into the existing conditional statement in the template. It already says if is_search, so I am just going to append the other conditionals after that. What I want to say if(is_search) or-- and or is signified by two pipes like this--is_archive(), or is_category(), or is_tag().

With the change made, I'm going to save the template, go back to my browser, and reload this Category page. And you'll see that now, instead of the full content, we just have an excerpt for each post, which means we can see far more posts in a smaller page. But I also said I wanted to get rid of the featured image, because you can see the featured image still takes up quite a lot of space. To do that I am simply going to copy this existing conditional statement and append it to where the featured image is inserted. So I'll copy the entire statement, and then I'll find the featured image, which is all the way up here at the top. Right under

we have the_post_thumbnail.

And I need to wrap the_post_thumbnail in this conditional statement, so I'll paste the statement in. Now all we have to do is end it so that the conditional stops, lets say And now what I'm doing is I'm saying if this is search archive, an archive, a category archive, or a tag archive, then display the_post_thumbnail, which is exactly opposite of what I want to say. So what I need to do is reverse the statement so that we change it from saying it this is search to say if this is not search or is not archive, et cetera.

To do that I am going to wrap the conditional statements in another parenthesis, and I am going to put an exclamation point in front of it. So now we're saying if it's not one of these conditionals then show the_post_thumbnail. I'll save my new template and reload the page again and you see that now the featured images appear, and we have a much shorter category archive page. But when I go to the front page, you still have the is images, the full stories, and the featured images.

Here again you see an example of how rather than making huge changes and building things from scratch, we can reconfigure existing functions and just move them around to get completely different results.

Show transcript

This video is part of

Image for WordPress 3: Building Child Themes
WordPress 3: Building Child Themes

45 video lessons · 35153 viewers

Morten Rand-Hendriksen
Author

 
Expand all | Collapse all
  1. 6m 59s
    1. Welcome
      1m 6s
    2. Using the exercise files
      1m 34s
    3. What you need to know before watching this course
      1m 29s
    4. Getting the right tools for theme creation
      2m 50s
  2. 17m 2s
    1. What is a WordPress child theme and when should you use it?
      2m 38s
    2. Picking a parent theme
      3m 55s
    3. Making sure you have the Twenty Twelve parent theme
      1m 50s
    4. Creating and activating a basic child theme
      4m 20s
    5. Importing parent theme styles
      4m 19s
  3. 16m 2s
    1. Using the developer tools
      3m 53s
    2. Modifying existing styles
      4m 24s
    3. Adding space between paragraphs
      4m 7s
    4. Changing font family styles
      3m 38s
  4. 31m 47s
    1. Understanding the WordPress template hierarchy
      3m 12s
    2. Modifying existing templates
      2m 33s
    3. Moving the header image
      4m 29s
    4. Adding Related Posts feature to posts
      6m 26s
    5. Creating custom page templates
      5m 43s
    6. Using conditional statements for customized effects
      5m 41s
    7. Creating custom header, footer, and sidebar templates
      3m 43s
  5. 17m 5s
    1. Understanding the different index pages and what they do
      4m 6s
    2. Adding author, date, and time information to the index loop
      7m 15s
    3. Changing the appearance of category index pages
      5m 44s
  6. 43m 5s
    1. Introducing functions.php
      3m 24s
    2. Overriding existing functions
      3m 23s
    3. Adding pagination to index pages
      5m 49s
    4. Adding to existing functions
      3m 21s
    5. Adding a new footer menu to Twenty Twelve
      6m 24s
    6. Adding a new widgetized area to pages
      4m 9s
    7. Adding static content to the sidebar
      7m 44s
    8. Replacing existing functions
      2m 36s
    9. Adding a Google font through a function
      6m 15s
  7. 10m 24s
    1. Adding new featured image sizes
      5m 41s
    2. Adding featured images to posts and pages
      4m 43s
  8. 31m 1s
    1. Adding a welcome message to the front page
      1m 22s
    2. Displaying page content in an index page
      7m 42s
    3. Hooking in a featured image
      4m 34s
    4. Making the welcome message responsive
      6m 27s
    5. Restricting content to the first page of the blog
      4m 22s
    6. Adding a jQuery function to show or hide the welcome message
      6m 34s
  9. 10m 23s
    1. Adding a custom favicon
      3m 58s
    2. Adding a custom screenshot
      2m 29s
    3. Adding footer information
      3m 56s
  10. 7m 14s
    1. What to do when a child theme crashes your website
      4m 38s
    2. Updating parent and child themes
      2m 36s

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 3: Building Child Themes.

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 preferences from 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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

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.