Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I have a photography website with just two categories, 'Lifestyle' and 'Food'.

I have two problems:

  1. How to display the content

I have a category group called 'photoCategories' to which I have assigned two categories 'Lifestyle' and 'Food'. I also have a Category field 'imageCategory'.

At the moment I have two Entries, one for Lifestyle and one for Food and I have linked to the appropriate category in the category field.

I have a 'category' template but I can't figure how to pull the appropriate content based on the URI and how to pull All content (within) the category group for when the user selects All?

  1. My navigation needs to look as follows:

Homepage (Single) All Images ('images' Channel) Lifestyle Photos ('images' Channel) Food Photos ('images' Channel) About Us (Single) Contact Us (Single)

Any advice is very much appreciated.

Thanks

Martin

share|improve this question

2 Answers 2

It sounds like you're pretty close. I'll work off of the assumption that you want the URLs to be structured like this:

/images

/lifestyle

/food

…and an individual image will be at /images/{image slug}.

Like you've done, I'd create a category group called photoGalleries. I'd set the URL format simple to /{slug} and a max level of 1. The two categories can then be added to that.

The images channel would have a URL format of /images/{slug}.

By setting up categories and the channel like this, Craft will automatically create variables when it matches those paths. You can then use these variables to do practical things.

To show images by category, you'll need to use to .relatedTo() method. When Craft matches a category route, it will create a category variable which can be passed into this method. In the template for a category, you'll need code like this:

{% set images = craft.entries.section('images').relatedTo(category).find() %}
{% for image in images %}
    <img src="{{ image.url }}">
{% endfor %}

This asks Craft to find any image which has been categorised by (related to) a specific category.

You can then create a simple images listing via a template for /images. If you wanted to get really fancy, you could output what categories an image is under. To do that you'd need code like this.

{% for image in craft.entries.images.find() %}
    <img src="{{ image.url }}">

    <ul>
    {% for category in craft.categories.relatedTo(image).find() %}
        <li><a href="{{ category.url }}">{{ category }}</a></li>
    {% endfor %}
    </ul>
{% endfor %}

Hope that gets you going.

share|improve this answer

Apologies for the "Answer" but the comments have a way too short character restriction...

I've been away for a few days so only just getting back to this. I'm still not getting any content pulled through following your suggestion. I've even gone back to a clean slate (install) but still struggling.

Just to clarify: I (now) have a Category group called "stmimagecategories". I have assigned an Asset field to this group called "imageUpload". I have created a Category field called "imageCategory".

My 'Section' is called 'Gallery' and I have assigned the 'imageCategory' field to that section.

I imagine the clients workflow would be to use the 'Categories' menu and subsequent Modal to dump a load of images into the appropriate category using the 'imageUpload' field.

So, what I need is... User creates a new Gallery entry called say "Panoramas". They add a title, bit of descriptive text and then select 'Panoramas' from the 'imageCategory' field.

I have the above set-up but the required template syntax to pull the content of the "imageCategory" field is blowing my mind :(

Further, the 'page needs to know what to show based on URL.

If you can help further with this I would be very much appreciate it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.