Home › Forums › General Issues › Creating an array of one field across entire site
First of all I’m not sure if I will explain this properly because my knowledge of this sort of thing is minimal to say the least so I would love some advice on how to approach my scenario.
The setup
I only have one layout for my entire site. In ACF, I have a sub field within a repeater (just a text heading) called “section_title”. There will be multiple instances of this on one page. Every page will have these custom fields.
My Needs
I need to create a mega menu (a simple unordered list) where these section titles will be listed as links under the parent link. My mega menu must display a link a standard link to the About page and list links to each section underneath so for example:
<ul>
<li><a href="">About</a>
<ul>
<li><a href="">Section 1</a></li>
<li><a href="">Section 2</a></li>
<li><a href="">Section 3</a></li>
<li><a href="">Section 4</a></li>
<li><a href="">Section 5</a></li>
<li><a href="">Section 6</a></li>
</ul>
</li>
</ul>
My Question
Ideally the menu must auto-populate. So if there is a page created and has a section with a title, automatically create the page link (as the parent) and add links to every section that exists on that page within the mega menu.
I use WP-Menu’s regularly but don’t think this part of WP can help automate the adding/removing of a ACF sections within any page and really unsure if this can be done or how to approach it. Would really love some advice from people in the know…
Well after thinking a lot about this, I’ve ended up using jQuery to solve my problem whereby it alters the links itself. This can at least give me the option of having a manual navigation using WP Menus.
I think what I’m shooting for is overly complex but it would be good to know if what I’m asking for is feasible in terms of auto-populating a menu.
FYI I used this bit of code to dynamically alter the menu links:
// Alter the links in the navigation so that the page doesn't reload
$(".nav a[href*='" + window.location.pathname + "#']").map(function(){
var currentsection = this.href.split('/').pop();
this.href = currentsection;
});
Hi @egr103
Without fully understanding your data and theme setup, I can’t be of much help, but I would guess that a jQuery solution is a pretty smart one.
This will then dynamically create the links based on the page’s content. It is actually the same logic that I use on the ACF docs page to create the ‘on this page’ links.
Hope that reassures you.
Cheers
E
The topic ‘Creating an array of one field across entire site’ 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.