Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialFinanigan A.
930 PointsInstead of Art I'd like to do Photographs. What changes must I make to the .php files to reflect this?
I'd like to create a page showcasing photographs and artwork that's not for sale as in the example here. What do I change in the .php files before I upload them to my own server?
2 Answers
Tyler Anderson
15,102 PointsHey Finanigan,
If you followed the course How to make a website with WordPress, then you should have all the files you need to make the appropriate changes. We essentially just change names from Art to Photographs
Step 1 The first thing you need to do is change the post_type from art to photographs If you have the post type UI plugin installed then go to the following:
At the bottom of the admin area click CPT UI --> Manage Post Types --> Click edit to edit the post type. From there change art to photographs on post type name, label and singular label. Please make sure the p in photographs is not capitalized. After you are finished with the changes click save custom post type.
Step 2: Advanced Custom Fields (if installed);
Next we need to change the custom fields section of WordPress. Click Custom Fields -->Click Art ( or the name you named it).
From there we need to change the location Rules for that Field group: make sure you select photographs after that click update.
Step 3. Edit PHP fields
you will need to change the files names from art to photographs
so with that said change the follow PHP file names:
content-art.php
, art.php
, and single-art.php
TO
content-photographs.php
, photographs.php
and single-photographs.php
These changes read the post_type name and files
the next part is inside the php files, you will need to change.
Step 4:
Edting photographs.php
and single-photographs.php
In the php file photographs.php edit the following. We need to change the template name for pages section in wordpress first. At the top of photographs.php change the following:
Template Name: Art Page TO Template Name: Photographs Page Next Assuming you didn’t change the code in it at all yet we will need to change the array names and template name.
online 40 in the array section of the file, change
'post_type' => 'art',
TO
'post_type' => 'photographs',
This line calls in the post type you changed earlier which should be photographs Next Then on line 48 change:
<?php get_template_part( 'content', 'art' ); ?>
TO
<?php get_template_part( 'content', 'photographs' ); ?>
This line calls in the advanced custom field’s information from content-photographs.php Click save
The last file you change is single-photographs.php
on line 8 change the template part from
<?php get_template_part( 'content', 'art' ); ?>
TO
<?php get_template_part( 'content', 'photographs' ); ?>
Same thing from photographs.php Click save.
Template page change The very last thing we need to change is the display part in WordPress pages. Go to the pages section in word press and select the page you want your Photographs to show on. On the template part in page attributes change default template to photographs page. Click update.
That’s it and you now can start adding photographs to your WordPress site.
Hope this helps
-tyler
Finanigan A.
930 PointsWow! Thank you for such a lengthy and detailed response, Tyler! Much appreciated. I shall follow the above steps.
- Finanigan