-
AuthorPosts
-
May 9, 2017 at 10:06 am #790107
Hi,
I need to show categories in the class for the article in the post grid list (http://kriesi.at/themes/enfold-2017/blog/blog-default/)
Can you help me?May 9, 2017 at 2:42 pm #790299Hey marcomila,
Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look.
Best regards,
VictoriaMay 9, 2017 at 2:53 pm #790311Hi,
here the websiteThe site is under construction for the moment.
CheersMay 9, 2017 at 4:10 pm #790414Hi marcomila,
Is this the page where you are trying to add categories?
You can give us temporary admin access to your website in the private content box below, we will not publish your site, no worries :)Best regards,
VictoriaMay 9, 2017 at 4:13 pm #790416Hi,
yesMay 9, 2017 at 7:36 pm #790529Hi marcomila,
But you have categories there. I am not sure I understand what you need to do here. Or did you get it solved already?
Best regards,
VictoriaMay 9, 2017 at 8:03 pm #790547As you can see there are categories visible for every single post, but i need to have the category name in the article class, in the html.
I mean somethig like this:
<article class=”Category-name category-name-2 …”>How can i add this??
May 9, 2017 at 9:45 pm #790623Hi,
That would require to modify the shortcodes template.
You can use a child theme and the following codeand then you can go ahead and try do those changes. For exmaple, after modify you can use get_category_id to load the id or name as per your needs
Best regards,
BasilisMay 9, 2017 at 10:13 pm #790649I’m using a child theme.
I’m working on postslider.php, where I found this line:
$output .= “<article class=’slide-entry flex_column {$style} {$post_class} {$grid} {$extraClass} {$thumb_class}’ $markup>”;I think I can add a code in this line to show the category, isn’t it?
Which code?May 10, 2017 at 8:44 pm #791333Hey, anyone knows a solution?
May 11, 2017 at 4:23 pm #791714Hi marcomila,
I see you have the classes added already. Great job! Anything else left to do?
Best regards,
VictoriaMay 11, 2017 at 4:30 pm #791716Hi,
the classes you read are the results of a custom fields.
I’m not able to add the category in the class.Anyway, I’ve got another question: How can I sort the post category like this:
parent, child category, …
Now are sorted for their ID in the breadcrumb, and alphabetical in the post grid.
Any idea?May 12, 2017 at 12:14 pm #792239Hi marcomila,
To sort post how you want you need to modify the query that gets posts from the database.
To add categories as a class you need to take this code in loop-index.php:foreach((get_the_category($the_id)) as $category) { if ($category->category_parent == 0) { $parentscategory .= ' <a href="' . get_category_link($category->cat_ID) . '" title="' . $category->name . '">' . $category->name . '</a> '; //$parents= get_category_parents( $category->cat_ID, true, ' » ' ); }else{ $parents.=' <a href="' . get_category_link($category->cat_ID) . '" title="' . $category->name . '">' . $category->name . '</a> '; } }
And use it to make a string with classes and add them to “
May 12, 2017 at 12:22 pm #792242Hi Victoria,
thanks for your reply.
Can you explain what you mean with “And use it to make a string with classes and add them to “?
Can you write an example please?May 14, 2017 at 10:59 am #792883Hi marcomila,
You have this loop, going through all categories of the post, you want their names as class, right? So use their names in a space separated string and assign it as a class.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.