jhyaps
August 13, 2023, 5:43am
1
Hi, I found that ciwcly filter displays posts and filter as per the categories but, can it be possible to display the sub categories of the relatable category.
Let me clear this statement
Suppose i have Men (Parent Category) and Hair style , Hair color, Hair cut are the sub category of the men, In the cwicly themer under archive page of Men i want to show posts form men category with the filter showing a sub category. Is this possible ?
Thank you
Hi @jhyaps ,
Thank you for bringing this up!
At present, the required logic for implementing a dynamic sub-category filter within a designated parent category has not been integrated.
Rest assured, this is something that we definitely plan for!
Moving this to planned feature requests.
jhyaps
August 13, 2023, 3:30pm
3
Hi, @Araminta just a curiosity, As my client asked me to implement this type of filter using custom code, can I do with shortcodes ?
What i have tried earlier in other project ?
In my some other project beyond cwicly, i have created a same type of filter using boostrap 4 tabs layout. Is it possible to implement same concept in this cwicly using shortcodes ?
Or any other better solution to do ?
Thank you for getting back to me, @jhyaps .
Could you possibly detail what part of the filtering you would want to achieve with shortcodes?
Thank you in advance.
jhyaps
August 15, 2023, 4:59am
5
Hi @Araminta ,
As i mentioned earlier, i want subcategories filter. but i want to use shortcode … Let me show you some example
<?php
/**
* Add Sub Category Filter
* shortcode ex. [subcategories_filter]
*/
// Add Shortcode
function subcategories_filter_shortcode() {
ob_start();
?>
<section class="section">
<div class="container">
<div class="row layout-regular text-center">
<div class="col-12">
<h2 class="text-white">Sub Categories</h2>
</div>
</div>
<div class="row">
<div class="col-12">
<?php
$category = single_term_title("", false);
$catid = get_cat_ID( $category );
$args = array('child_of' => $catid);
$categories = get_categories( $args );
$category_object = get_category($catid);
$category_slug = $category_object->slug;
?>
<ul class="nav nav-tabs mb-5" id="categoryTabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="all-posts-tab" data-toggle="tab" href="#all-posts" role="tab" aria-controls="all-posts" aria-selected="true">All</a>
</li>
<?php
// Loop through categories and create tab links
foreach ($categories as $category) {
echo '<li class="nav-item">';
echo '<a class="nav-link" id="' . $category->slug . '-tab" data-toggle="tab" href="#' . $category->slug . '" role="tab" aria-controls="' . $category->slug . '" aria-selected="false">' . $category->name . '</a>';
echo '</li>';
}
?>
</ul>
<div class="tab-content" id="categoryTabsContent">
<div class="tab-pane fade show active" id="all-posts" role="tabpanel" aria-labelledby="all-posts-tab">
<?php
// Display all posts
$all_posts = new WP_Query(array(
'category_name' => $category_slug,
'post_status' => 'publish',
'posts_per_page' => -1
));
echo "<div class='contents p-5'>";
if ($all_posts->have_posts()) {
while ($all_posts->have_posts()) {
$all_posts->the_post(); ?>
<h6 class="chapter" for="<?php the_title(); ?>">
<a href="<?php the_permalink() ?>" class="btn-link"> <?php the_title(); ?></a>
</h6>
<?php
}
}
echo '</div>';
wp_reset_postdata();
?>
</div>
<?php
// Loop through categories and create tab content
foreach ($categories as $category) {
echo '<div class="tab-pane fade" id="' . $category->slug . '" role="tabpanel" aria-labelledby="' . $category->slug . '-tab">';
// Get posts from the subcategory
$posts_in_category = new WP_Query(array(
'category_name' => $category->slug,
'post_status' => 'publish',
'posts_per_page' => -1
));
echo "<div class='contents p-5'>";
if ($posts_in_category->have_posts()) {
while ($posts_in_category->have_posts()) {
$posts_in_category->the_post(); ?>
<h6 class="chapter" for="<?php the_title(); ?>">
<a href="<?php the_permalink() ?>" class="btn-link"> <?php the_title(); ?></a>
</h6>
<?php
}
}
echo '</div>';
wp_reset_postdata();
echo '</div>';
}
?>
</div>
</div>
</div>
</div>
</section>
return ob_get_clean();
}
add_shortcode( 'subcategories_filter', 'subcategories_filter_shortcode' );
In here I have used bootstrap 4 tab layout.
As you see here this shortcodes is placed under archive page in normal wordpress theme but how to do this in cwicly. Since i have created a archive themer in cwicly how to placed this shortcodes there.
Hi @jhyaps ,
You may find this tip useful:
As there have been a few posts where questions around this came up, I thought it may be useful to show the four most common ways you can add custom code that work well with Cwicly.
1. Child theme functions.php
Download the child theme and install from here (only do this for new websites unless you know how to transfer your theme customisations to the child theme):
Cwicly.com dashboard - Add child theme & make links obvious - #9 by StrangeTech
Edit the functions.php file and add your custom …
Note there are two steps to this:
Define the shortcode (see the tip above)
Add the shortcode to the archive (this can easily be done using a shortcode block)
1 Like
jhyaps
August 15, 2023, 1:31pm
7
Thank you for the tips . It Actually helps.
Thankyou @Araminta @StrangeTech
Also hoping for the future update regarding this features by the cwicly itself.
1 Like