Each post showing the custom fields of all created posts

It’s the first time that i try to use custom field and query loop…and i will have 3 pages that will be identical in layout and for each page they will change: the main title, the description, the images of the cards and their title.

I thought about creating a general template for these 3 pages. it is correct? So i tried and i create 3 posts (with pods) with these custom fields (title - main - description - image tab and image tab title). Basically the template will have to take these custom fields and show me the correct custom fields of each post created. I created a query loop for the container of the template that i get the custom field for main title, description etc…

It works, only that when I go to view each of the created posts (which takes the layout and custom fields of the template), each post shows me all the custom fields of all the posts, not just those of the post to which the custom fields are assigned. So I see for each post (3 main titles - 3 descriptions etc…). Where did I go wrong? Thank you Davide

Hi Davide

Sounds to me like your element structure in Bricks is wrong.

Can you post a screen shot of your element structure in the template in Bricks? Then we can look at how you set it up.

Cheers

Patric

1 Like

Of course i have a lot of confusion in this moment…i’m tring to understand how works customfield query loop and how to menage with the structure of the site in Bricks.

Maybe there are some rules to follow that i don’t know and i din’t find any place where they say something like: for make this you have to make this and that…so…i try and i try and of course i asked here if someone could help me to understand to manage this stuff, like this the next time i know and i will make it in the right way…thanks for you help…here the image…structure, the image of the page like it showing, and the page of the query loop on the main container.

The blue text it’s “Heading” - the big one text it’s “Lede”
Thanks again



Ok, I try to explain.

The result of your structure is exactly the way it is supposed to work. There is nothing wrong with it.

You have created 3 posts, each having a different content in the fields you created.

Now if you create a query loop for the posts, Bricks finds all the posts that qualify for the query settings and then it runs through the elements that you put under / within the query loop.

In your case, it finds three (individual) posts and runs therefore the query loop three times on the same page.

This is the reason, why in your page, you see all three posts and not only one.

I think where you misunderstood is the usage of a query loop and of a template.

Usually, a query loop is used to show ALL the existing posts that qualify for the query settings. Think of it like a blog page that shows all existing posts, each of them can be clicked on and then the details of the selected post is shown on a new page.

Or in your case, a page that shows the title of all three posts and if the user clicks on one of the titles, the page with all the details of the selected post is shown. If the user clicks on the back button in the browser, the page with all 3 posts is shown again and the user can click on another post to see the details.

The template is usually used to show the details of such a selected post (= blog post layout). That is done via the condition settings of the template itself. For example, you define in the template settings that this template shall be used for all post types called „products“.

Then, if a user clicks on a post that belongs to the post type „products“, Bricks loads the specific template for that post type and renders the data from that post with the blog post layout it loaded in the template.

This article explains the concept of the templates:

You find more information about templates and query loops in the Bricks Academy, e.g. for the query loops

To summarize, you are on the right way. At the moment you have created the page that shows ALL existing posts. Now you have to also create a template for the post types.

Cheers

Patric

Hi Patric you are very kind to help me…thanks.

The thing I didn’t quite understand is this, if I have 3 categories (excursion - Walking - Events) and for each category I have different posts.

Do I have to create 3 different templates for each category?

Because in any case even now that I’ve created the posts, both the general template that shows me the previews of my posts and the internal template of each single post show me all the elements of each post.

Because here what i need…
. The “page” (which would then be a template) that will take the excursions category will only have to see the posts in the excursions category.
. The “page” (which would then be a template) that will take the events category, will have to see only the posts of the events category.
. The “page” (which would then be a template) that will take the Walking category, will only have to see the posts in the Walking category.

So since they have the same layout, I thought of creating one template for all three pages and using a query loop to take these categories and show me the previews of the posts and the custom fields only for the category I chose to see, not for all . Instead a template shows me all the categories.

So I wonder is there the method to show 3 different categories (as I told you above one category for each page) on a single template, or should I create a template for each category so three?

Same thing for individual posts? do I have to create 3 different templates for each category of posts?

One last thing, the link that is given to the post preview card which will then open the post’s internal page on click. How to set: “Dynamic data” > {post_url} ?

Thank you so much for your help
Davide

Dear Davide

No, you can use one template for many categories.

In the screen shot from your query loop, I see that you include all three categories.

If you do that, then Bricks will show you all posts that are at least in one of those categories. To only see one category, only use one category in the query settings, for example Events. Delete all the other categories in the query settings.

Then Bricks will only show the posts that have the category Events.

Cheers

Patric

ok, yes i understand, but how can i see the others categories from the same template? if i say to this template to show me only the events category?
Thanks
Davide

Hi

You have to separate the query loop from the template.

The query loop is used to show the available posts from a post type (for example Servizi). In the query loop, you can add the category parameter if you want to further limit the posts to be shown.

If you click on such a post that is shown, the template is loaded with the data from the post selected.

So if you want to have 3 individual pages showing all Events posts, all Walking Tour posts, etc., then you have to create 3 individual pages and in each page you make one query loop with the chosen category.

These 3 pages have nothing to do with the template.

For the template to be used for all 3 categories and the custom post type Servizi, you just have to define in the template settings in the condition that it shall be used for the custom post type Servizi.

Is it clear now?

Cheers

Patric

Maybe this helps you to understand the process

Ah ok, thinking that Bricks could also make me fly :slight_smile: (joking).
Believing that with 1 template you could manage 3 different post categories and display only the post categories that I wanted to display and not all of them. (always and only from 1 template).
Instead, I create 3 pages (it’s useless to make 3 templates) and for each page I add queries for that specific post category that should display the page and the related custom fields.

Same thing for the single posts of each category, instead I make 3 single post templates each for each category.

However it could be a powerful implementation for the future power using only one template to do things (like what I have to do).

Is there the possibility to hide for some posts only; an element with has custom field that in same case (so in some posts) i don’t need it?

Thanks so much for everything.

Hi Davide

No, actually you don’t have to make three templates. I tried to explain that you can use 1 template for all three categories.

It seems my explanations are too difficult to understand.

Maybe this video will help you:

Cheers

Patric

Thanks Patric…you have been very helpful, with this last video I understood where I was wrong and everything seems to work as it should. One thing is not clear to me, how can I have on the template archive a different main title for each post category it shows me.
Like this:
. Main title “The Excursions” (category excursions) and above post 1 from (category Excursions) - post 2 from (category Excursions) - post three from (category Excursions)

. Main title “The Events” (category events) and above post 1 from (category events) - post 2 from (category Excursions) - post 3 from (category events) - post 4 from (category events) - post 5 from (category events)

. Main title “The Walking Tours” (category walking tours) and above post 1 from (category walking tours) - post 2 from (category walking tours) - post 3 from (category walking tours) - post 4 from (category walking tours)

Thanks Davide

i got it…i don’t know why i add everywhere query loop ahahh in this case it is not needed :wink:
Thanks again…in the end i will show you the site that you help me to create…and right now that i understand basically how it works and i will save a lot of time building sites.
Thanks again :wink:

1 Like

If I understand you correctly, you want to have a different title depending on the category?

You can achieve that with a condition.

You would make three text elements with the three different title texts and then add to each a condition to only show it if the post condition is the one for the title.

Similar to something like this:

condition

I can’t check it if it works. You have to try it. It is a good way to learn about conditions.

Cheers

Patric

i say to the title of the archive template to get {post_terms_categorie_offerte} and to the description {term_description} from the main category that i create with Pods. {term_description} it’s a custom field that i add in the categories page on the backend.
It works fine, but i have to study your solution, of course it will be a start for understand how the conditions works.
Thanks again Davide

1 Like