Skip to content

Instantly share code, notes, and snippets.

View crispyabsurdist's full-sized avatar
🍻

Markus Hedenborn crispyabsurdist

🍻
View GitHub Profile
@crispyabsurdist
crispyabsurdist / filtering-acf-repeater-sub-field.php
Created March 7, 2024 15:42
wp_query ACF repeater sub_fields
<?php
/**
* Filters the posts by the specified author and returns the matching post IDs.
* If no matching posts are found, it returns a message indicating that no posts were found for the specified author.
*
* @param string $search_author The author to filter the posts by.
* @return array|string The array of matching post IDs or a message indicating no posts were found.
*/
if (!empty($search_author)) {
@crispyabsurdist
crispyabsurdist / alpinejs-contrast-color.blade.php
Last active February 20, 2024 13:10
alpinejs contrast setting text-color and border-color depending on background-color
<div class="bg-{{ $backgroundColor }}" x-data="colorContrast()" x-bind:class="textColorClass">
<p>Text som ska ändra färg beroende på bakgrundsfärg</p>
<a class="leading-non inline-block rounded-3xl border px-6 py-4 text-xs font-bold no-underline" href="{{ $card['card_button']['url'] }}" x-bind:class="borderColorClass">
{{ $card['card_button']['title'] }}
</a>
</div>
<script>
document.addEventListener('alpine:init', () => {
Alpine.data('colorContrast', () => ({
@crispyabsurdist
crispyabsurdist / index.html
Created January 4, 2024 06:15 — forked from cdsaenz/index.html
Demo Alpine JS and Fetch from Remote API
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alpine Ajax test</title>
</head>
<body>
<h1>Users API Retrieval Test</h1>
@crispyabsurdist
crispyabsurdist / gutenberg.txt
Created December 5, 2023 07:09 — forked from chrismccoy/gutenberg.txt
Gutenberg Resources
How to Read WordPress Block Content Programmatically
https://www.ibenic.com/read-wordpress-block-content-programmatically/
Creating a Server-Side Rendered ACF Field Block for WordPress
https://wpblockz.com/tutorial/learn-gutenberg-block-building-create-a-block-that-renders-an-acf-field/
Coding Gutenberg Toggle Control Block Settings
https://wpblockz.com/tutorial/wp-gutenberg-editor-controls-form-toggle/
Remove the default block patterns from WordPress
<?php
public function postFilter()
{
// Define custom post type and taxonomies
$post_type = 'product';
$taxonomies = array('brand', 'category');
// Get the current page number
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
@crispyabsurdist
crispyabsurdist / read-N-rows.sh
Created February 3, 2023 18:55
Get the first N lines of a file
head() {
# Usage: head "n" "file"
while IFS= read -r line; do
printf '%s\n' "$line"
i=$((i+1))
[ "$i" = "$1" ] && return
done < "$2"
# 'read' used in a loop will skip over
# the last line of a file if it does not contain
@crispyabsurdist
crispyabsurdist / mixin-icons.scss
Created January 24, 2023 11:14
scss mixin for icon element
@mixin svg-icon($name, $height: 24, $width: 24, $color: $color-primary) {
-webkit-mask-size: contain;
-webkit-mask-repeat: no-repeat;
-webkit-mask-position: center;
height: calc($height / $base-font-size) + rem;
width: calc($width / $base-font-size) + rem;
background-color: $color;
mask-image: url(~@images/icons/#{$name}.svg);
background-size: cover;
mask-size: contain;
@crispyabsurdist
crispyabsurdist / fluid-typography.scss
Last active January 24, 2023 11:14
fluid typography in scss
// Define the base font-size and line-height
$base-font-size: 16px;
$base-line-height: 1.5;
// Define a mixin for setting font-size and line-height in rem units
@mixin font-size-rem($size, $line-height) {
font-size: ($size / $base-font-size) + rem;
line-height: ($line-height / $size);
}