Skip Navigation

[Resolved] I want to have a container background color to change color per post type

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by pierreB-9 10 months, 3 weeks ago.

Assisted by: Waqar.

Author
Posts
#2609013
Post author.jpg

Tell us what you are trying to do?
I have TWO issues
1) I have a view that display Customs Post Type loop with two types (Custom fields = Paper or Opinion) and I would like to set a different color wether the type is a "Paper" and a different color when this CPT is an "Opinion"

2) On my search fields I would like to use the "post author" but it is NOT on the available fields list

Is there any documentation that you are following?
I have watch many of your toolset video and also searched the issues database and found nothing that related to my exact issues

Is there a similar example that we can see?

What is the link to your site?
The view I have build is avaible here:
hidden link

#2609143

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

container-block-id.png

Hi,

Thank you for contacting us and I'd be happy to assist.

1) On my test website, I was able to set different container background colors to posts based on their post types, by following these steps:

a). I wrapped the contents of the view's loop item in a 'Container' block.

b). In that 'Container' block's 'ID & Classes' section, I included the following shortcodes in the 'ID' field:
( example screenshot attached )


[wpv-post-type]-[wpv-post-id]

This way, each post container will now have a unique ID assigned to it, that will start from '{post type slug}-'.

c). In the view block's 'Custom CSS' field, I included some custom CSS code to apply different background colors to these containers, based on the text their IDs start from. For example, in my test view, I had two post types with slugs 'post' and 'book', so the CSS code looked like this:


div[id^="post-"].tb-container {
background: green;
}

div[id^="book-"].tb-container {
background: blue;
}

The above CSS code will set all 'posts' backgrounds to 'green' and all 'books' backgrounds to 'blue'. Feel free to adjust the post-type slugs and the colors, as needed.

2) Your observation is correct and there is no built-in search field filter available for the post author. This will require some custom code workaround and you'll find details on this in this other support thread:
https://toolset.com/forums/topic/add-author-in-view-search-filter/

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2609731

Hi Waqar,
Thank you very much for your responses. This helps me a lot. I have two additional issues on the solutions you have provided

1) for the first issue "Displaying different color of the background container, since I amusing a CPT "Papers & Opinions" (slug = 'paper-opinion' however I do use a customs field as sub-type which is the type I need to use)
question how can I make it work?

2) for the post author it looks like the right solution,
- I just need to only display the real author instead of all the users on the site
- I wish to add a label to this filter but it doesn't have the same possibility as the other filter field (the one I have added is not properly aligned even though I have added padding & margin
hidden link

Last not least I wish to replace the current archive template (hidden link) with the new page "new-publications-archive" without breaking anything... how do you advice me to proceed?

Thanks again in advance with your great support answer

New threads created by Waqar and linked to this one are listed below:

https://toolset.com/forums/topic/split-replacing-archive-with-the-page-view/

#2610137

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

1) To include a custom field value to this identifier ID, you can make use of the 'wpv-post-field' shortcode:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-field

For example:


[wpv-post-type]-[wpv-post-field name="wpcf-field-slug"]-[wpv-post-id]

The format of the created ID would be 'book-value-1234'.
( where 'book' is the post type slug, 'value' is the value from the custom field 'field-slug', and '1234' is the current post's ID )

2) If you'd like to limit the list of users to only a particular user role(s), you can use the 'role__in' attribute, in the 'get_users' function:
https://developer.wordpress.org/reference/functions/get_users/

In the code of the custom shortcode, you'll have this line:


$users = get_users();

To limit the users to only a particular role, e.g. 'author', you can update it to:


$users = get_users( array( 'role__in' => array( 'author' ) ) );

The field label 'Search by author' is now showing the same as the other field labels, so looks like you've managed to make it work.

As for your question about replacing the archive page with the regular page with a view, I've created a separate ticket for it. Will follow up on that ticket, shortly
( ref: https://toolset.com/forums/topic/split-replacing-archive-with-the-page-view/ )

#2610171

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.