Skip to content

Instantly share code, notes, and snippets.

Avatar

thisbit thisbit

View GitHub Profile
@thisbit
thisbit / post_by_view.php
Last active Nov 24, 2022
generateblocks_query_loop_args ordered by post_views_count
View post_by_view.php
<?php
/*
* GenerateBlocks & GeneratePress implementation of post ordering based on post views.
*/
// set the view counter
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
@thisbit
thisbit / objects.php
Created Oct 19, 2022
learning php objects, basics
View objects.php
<?php
// objects and classes
/**
* Flexible but longform
*/
class Person {
private $name;
private $age;
@thisbit
thisbit / back_to_top.php
Last active Oct 3, 2022
Back To Top Button
View back_to_top.php
<?php
/**
* Back to Top button that appears once one scrolls past the full viewport height
* Drop this function into your functions.php, code snippets plugin ...
* You should not need to change anything, but in case your theme does not have #page id in one of top dom elements, change to the one you have
* CSS you can normally edit as you like
*/
function back_to_top() {
?>
@thisbit
thisbit / hide-show.css
Last active Sep 27, 2022
hide show anything on scroll
View hide-show.css
/* we use variables to that hiding fits perfectly with the nav and aside height/width */
:root {
--nav-height: 90px;
--sidebar-width: 120px;
}
/* menu setup */
body nav {
position: fixed;
top: 0;
@thisbit
thisbit / gb_query_events.php
Last active Oct 23, 2022
Upcoming events with generateblocks
View gb_query_events.php
<?php
/**
* Event query with GenerateBlocks
* Show only events that are happening in future, and order them from sooner to later
* @link https://community.generateblocks.com/t/generateblocks-query-loop-args-slowing-pages-way-down/903/9
* @link https://community.generateblocks.com/t/use-gb-query-loop-for-related-post/688/2
*/
function gb_query_events( $query_args, $attributes ) {
@thisbit
thisbit / toggle.css
Last active Oct 28, 2022
GenerateBlocks Toggle
View toggle.css
.editor-styles-wrapper .gb-button-wrapper .gb-button.trigger,
.site .gb-button-wrapper .gb-button.trigger {
cursor: pointer;
user-select: none;
padding: 5px !important;
border-radius: 2em;
height: 25px;
width: 50px;
align-items: center;
color: #ddd;
@thisbit
thisbit / new-tabs.css
Last active Jan 1, 2023
New and improoved Tabs for GenerateBlocks
View new-tabs.css
/* Buttons as TABS */
.site .triggers .gb-button {
color: var(--contrast-2);
background-color: var(--base-2);
}
.site .triggers .gb-button:hover,
.site .triggers .gb-button:focus,
.site .triggers .gb-button:target,
.site .triggers .gb-button[aria-selected="true"] {
@thisbit
thisbit / tabs.css
Last active Aug 26, 2022
Tabs feature with GenerateBlocks
View tabs.css
.site .triggers > .gb-inside-container .gb-container {
color: var(--contrast-2);
background-color: var(--base-2);
}
.site .triggers > .gb-inside-container .gb-container:hover,
.site .triggers > .gb-inside-container .gb-container:focus,
.site .triggers > .gb-inside-container .gb-container.is-active {
color: var(--base);
background-color: var(--accent);
View webp-fallback.css
/* Old Browsers Use this - read Safari */
element.classname {
background: url("../images/image.jpg");
}
/* Chrome 66+, Edge 79+, Opera 53+, Android Brower 80+ */
@media screen and (-webkit-min-device-pixel-ratio: 0) and (min-resolution:.001dpcm) {
@supports (background-image: -webkit-image-set(url("../images/repozitorij.webp") 1x)) {
element.classname {
background: url("../images/image.jpg");
View gb-query-block-filter.php
<?php
// GenerateBlocks variant of pre_get_posts for the query block
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'custom-grid-class' ) !== false ) {
$query_args['meta_key'] = 'field_name';
$query_args['orderby'] = 'meta_value'; // better for strings
// $query_args['orderby'] = 'meta_value_num'; // better for numbers
$query_args['order'] = 'ASC';