Skip to content

Instantly share code, notes, and snippets.

@tdmrhn
tdmrhn / blc-posts-shortcode-add-author-arg.php
Last active February 26, 2024 16:33
Blocksy Posts Shortcode Add Author IDs arg
<?php
add_filter('blocksy:general:shortcodes:blocksy-posts:args', function ($query_args, $shortcode_args) {
if (isset($shortcode_args['author_ids'])) {
$author_ids = array_map('intval', explode(',', $shortcode_args['author_ids']));
$query_args['author__in'] = $author_ids;
}
return $query_args;
}, 10, 2);
@tdmrhn
tdmrhn / blc-2-exclude-out-of-stock-products-upsell.php
Created February 23, 2024 11:44
Blocksy 2 Exclude Out of Stock products from related and upsells
<?php
add_filter( 'woocommerce_output_related_products_args', function ( $args ) {
$args['status'] = 'publish';
$args['limit'] = -1;
$args['stock_status'] = 'instock';
return $args;
}, 10, 1 );
@tdmrhn
tdmrhn / blc-2-mobile-pagination-numbers.css
Created February 23, 2024 06:12
Blocksy 2 Simplify Pagination Numbers in Mobile View
@media (max-width: 689.98px) {
[data-pagination="simple"] > div .page-numbers
{ margin: 2px; }
[data-pagination="simple"] > div .page-numbers:nth-child(3),
[data-pagination="simple"] > div .page-numbers:nth-child(4),
[data-pagination="simple"] > div .page-numbers:nth-child(8),
[data-pagination="simple"] > div .page-numbers:nth-child(9)
{ display: none; }
}
@tdmrhn
tdmrhn / blc-2-echo-content-block-if-acf-exist.php
Created February 17, 2024 12:40
Blocksy 2 Content Blocks + ACF condition
<?php
add_filter('blocksy:single:top', function () {
if (get_field('my-field')) {
echo do_shortcode('[blocksy-content-block id="XXX"]');
}
});
@tdmrhn
tdmrhn / blocksy-2-masonry-grid.css
Created February 15, 2024 12:22
Blocksy 2 Blog Posts Masonry Grid
[data-prefix="blog"] section .entries {
display: block;
--masonry-column: 3;
-webkit-column-count: var(--masonry-column);
-moz-column-count: var(--masonry-column);
column-count: var(--masonry-column);
}
[data-prefix="blog"] section .entries article {
display: inline-block;
@tdmrhn
tdmrhn / blc-2-add-related-brand-products-with-content-bocks.php
Last active January 24, 2024 11:15
Blocksy 2 Brand based related products with Content Blocks Hook + Code Editor Block
@tdmrhn
tdmrhn / blc-2-sticky-post-navigation.css
Created January 23, 2024 21:00
Blocksy 2 Sticky Post Navigation
@media (min-width: 1000px) {
// replace for CPT also replace CPT slug with project
// .single-project .post-navigation
.post-navigation { position: fixed; top: 47%; width: 100vw !important; max-width: 96vw !important; left: 2vw; right:2vw; }
}
@tdmrhn
tdmrhn / blc-2-add-content-block-in-shop-loop.php
Created January 23, 2024 10:13
Blocksy 2 Add a Content Block after certain shop loop item
<?php
add_action('woocommerce_after_shop_loop_item', function () {
if (wc_get_loop_prop('loop') === 3) {
echo '<li>' . do_shortcode('[blocksy-content-block id="XXX"]') . '</li>';
}
});
@tdmrhn
tdmrhn / blc-2-add-swipe-function-post-navigation.html
Created January 22, 2024 14:40
Blocksy 2 Add Swipe Function to Single Posts Navigation
<script>
const postNavigation = document.querySelector('.post-navigation');
let startX;
postNavigation.addEventListener('touchstart', e => startX = e.touches[0].clientX);
postNavigation.addEventListener('touchend', e => {
const diffX = startX - e.changedTouches[0].clientX;
const selector = diffX > 0 ? '.nav-item-next' : '.nav-item-prev';
@tdmrhn
tdmrhn / blc-2-product-brands-shortcode.php
Last active February 16, 2024 17:12
Blocksy 2 Product Brands loop Shortcode
<?php
add_shortcode('product_brands', function ($atts) {
ob_start();
$brands = get_terms(array(
'taxonomy' => 'product_brands',
'hide_empty' => false,
));
if (empty($brands)) {
echo 'No product brands found.';