Home › Forums › General Issues › How to insert a field on a CPT "homepage"
Hi again,
I have setup custom post types for a portfolio. Now I would like to insert a custom field in order to be able to change the background image on the portfolio page, not on each project page.
Thanks in advance
Francis
Hi,
You should setup options page and make field for portfolio background. When just use background field to portfolio template like this:
<?php the_field('fieldname', 'options');?>
In this case you will choose background only once, but it will be visible on each portfolio post.
Thanks Mariol,
Is there any possibility to have the background only for the portfolio page, as I did setup different background for the different projects pages ?
Thanks 🙂
Not sure what you want to achieve 🙂 You can create theme template only for portfolio page and use acf background field ONLY for that template.
Ok, I’ll try to be clear enough 😛
I created a archive-projects.php template. I want to have a background image only on that page. That is the portfolio page, the one where you see all the projects. I also created single-projects.php, which the template for each project pages. But for this one I know how to insert a background for each page. But for archive-projects.php, I don’t know because there is no way to edit that page in the admin. That is why I liked the idea of the options page 🙂
Am I clearer? 🙂
Yeah now its clear 🙂
Open your functions.php file and add this code if options page is not visible in WP menu
// register options page
if(function_exists('acf_add_options_page')) {
acf_add_options_page();
}
When create field group with field f.e.’portfolio_background’
When choose field group location -> Show this field group if [OPTIONS PAGE] is equal to [OPTIONS].
Inside archive-projects.php add
<?php the_field('portfolio_background', 'options');?>
That would be the way how to echo some field and control it if you don’t have page in WP menu.
Yeah in this case. or just acf 5 pro pack with options page included.
The topic ‘How to insert a field on a CPT "homepage"’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.