Home › Forums › Technical Theme Support › STAX Theme › Post Filters showing Categories not included in Selection
Tagged: filter, obb-filter-nav, posts
- This topic has 11 replies, 2 voices, and was last updated 2 months, 2 weeks ago by David Morgan.
-
AuthorPosts
-
August 11, 2024 at 4:53 pm #465666Lewis HackfathParticipant
I have used the posts block to display a selection of posts (Team Members) on a page.
I have only selected a few categories which relate to the office in which the Team Member Works at.
However the filter buttons are showing all categories that have posts.
I have attached an image for reference.Attachments:
You must be logged in to view attached files.August 13, 2024 at 12:16 am #465711Lewis HackfathParticipantAdditionally is it possible to change the colour of the active filter? so it is easy to identify which filter is currently in place.
August 13, 2024 at 8:32 am #465727David MorganKeymasterHi Lewis,
In order for the filters to work properly, you’ll need to setup a parent category with child categories beneath it. The child categories will act as your filters, and then you can select the parent category in the block setup options.
Changing the color of the active filter will likely need to be done using CSS. If you can provide a link to the page I’ll be happy to provide the CSS.
Thanks!
August 13, 2024 at 1:09 pm #465742Lewis HackfathParticipantThis reply has been marked as private.August 13, 2024 at 4:29 pm #465755Lewis HackfathParticipantAdditionally I have been asked if it is possible to sort in alphabetical order?
August 21, 2024 at 3:56 am #465994David MorganKeymasterHi Lewis,
The link to your site currently isn’t working.
For simplicity sake, you could update your workaround styles to this instead:
.team [data-filter=”.team”], .team [data-filter=”.news”], .team [data-filter=”.project”], .team [data-filter=”.director”] { display:none; }
However, you shouldn’t need to use this workaround. If you provide your WP admin login info I can take a look at your setup to see if your categories are setup properly for filtering.
Currently there is only the option to sort by Ascending or Descending (newest to oldest, or oldest to newest). We could update your plugin code with the option to sort alphabetically using our One Change service.
Thanks!
August 21, 2024 at 12:15 pm #466012Lewis HackfathParticipantThis reply has been marked as private.August 21, 2024 at 1:13 pm #466015Lewis HackfathParticipantHi David,
I’ve edited the OBB Plugin to allow for a “Order By” Field to be added to the Portfolio Block.
This is working and functional with the default setting being “date” but gives the options to order by date, title or type.I’ve attached the two files I’ve made the code changes in as I feel these would be awesome to add into production and wanted to pass them on.
August 21, 2024 at 1:58 pm #466016Lewis HackfathParticipantI was also able to edit the Nav Filter to only bring in categories of the posts in the WP_Query Object by updating the following in organic-blocks-bundle/classes/class-obb-portfolio.php
<div class="obb-filter-buttons wp-block-button"> <?php $terms = get_terms( array( 'taxonomy' => $taxonomy, 'object_ids' => wp_list_pluck( $portfolio_query->posts, 'ID' ), //added to retrieve only terms of the posts in the query 'hide_empty' => true, ) ); $count = count( $terms ); // This counts the number of categories. echo '<button class="obb-button wp-block-button__link secondary" data-filter="*">Show All</button>'; if ( $count > 0 ) { foreach ( $terms as $term ) { $termname = strtolower( $term->name ); $termname = str_replace( ' ', '-', $termname ); echo '<button class="obb-button wp-block-button__link secondary" data-filter=".' . esc_attr( $termname ) . '">' . esc_html( $term->name ) . '</button>'; } } // In the above foreach loop, the code will return all the values stored in $terms array. ?> </div>
August 22, 2024 at 4:57 am #466065David MorganKeymasterHi Lewis,
That’s great! Thanks for sharing your updates!
However, the files didn’t attach because PHP files can be uploaded. However, you could zip the files and attach the zip file, then we can implement your updates to the plugin.
Thanks!
August 22, 2024 at 12:48 pm #466070Lewis HackfathParticipantHi David,
Zip File Attached.
I’ve only added the code for the Portfolio Block however it could be used for other post display blocks.
Changes Made:
– Add “Order By” Field to Portfolio Block to allow ordering by Date, Type or Name
– Update Masonry Filter to only show Terms used on the posts being displayed
– Update Masonry Filter to not show the Term selected in the Block settings as there is already a “Show All” buttonAttachments:
You must be logged in to view attached files.August 28, 2024 at 3:41 am #466214David MorganKeymasterAwesome, thanks Lewis!
-
AuthorPosts
- You must be logged in to reply to this topic.