Custom fields question: one key, many values
-
I’ve been searching around but haven’t found a solution as yet.
I’m working on creating a portfolio for a client, and there’s a lot of content that’s repetitive…For instance, right now the source of each post would be something like this:
<div class="project"> <a href="https://domain.tld/images/project-one-1.jpg" rel="shadowbox[project-one]"><img src="https://domain.tld/images/project-one.jpg" /></a> <a href="https://domain.tld/images/project-one-2.jpg" rel="shadowbox[project-one]" class="hidden"></a> <a href="https://domain.tld/images/project-one-3.jpg" rel="shadowbox[project-one]" class="hidden"></a> </div> <div class="project"> <a href="https://domain.tld/images/project-two-1.jpg" rel="shadowbox[project-two]"><img src="https://domain.tld/images/project-two.jpg" /></a> <a href="https://domain.tld/images/project-two-2.jpg" rel="shadowbox[project-two]" class="hidden"></a> <a href="https://domain.tld/images/project-two-3.jpg" rel="shadowbox[project-two]" class="hidden"></a> <a href="https://domain.tld/images/project-two-4.jpg" rel="shadowbox[project-two]" class="hidden"></a> </div> ( and so on... )
After adding around five projects, and messing it up a bit, I thought about using custom fields. As you can see, the only bit that really changes between each set of links in a div is the project-name. Within each div, the class name “hidden” is applied to all links after the first one. Also, the number of links in each div isn’t constant. Project One could have 3 links, while Project Two could have 10.
I have three questions:
- I created a new key named project and gave it the value of project-one. So far so good.
For the second project, I used the same key project, and gave it the value of project-two.Here’s where I started facing problems. I know how to extract information if there’s just one unique value for each key. What does one do if the same key is repeated, with different values for each instance?
- I guess I need to define the number of links for each project. I considered setting adding this number with the project key. For instance, the value for the first project would be project-one [separator] 2, where the name is followed by a separator (a comma? a bar?), and a number.
How does one define a set of two related values within a single key?
- The third problem may not be a WordPress-related issue, but I would be grateful if someone could sort it out for me. Within each set of links in a div, the first div is slightly different from the rest, which have a class name “hidden” applied to each of them. I guess I need to use foreach or a counter in there somewhere, but doing them all together, but I got all confused with all of the issues together.
- I created a new key named project and gave it the value of project-one. So far so good.
- The topic ‘Custom fields question: one key, many values’ is closed to new replies.