Skip to content

Instantly share code, notes, and snippets.

View insaurabh's full-sized avatar
🎯
Focusing

Saurabh Ranjan insaurabh

🎯
Focusing
View GitHub Profile
@insaurabh
insaurabh / index.twig
Last active November 13, 2019 15:05
For craft-ajaxinate demo
{#
# File path : <root>/templates/news/index.twig ( default files of Happy Lager Demo Site )
# News index template
# -------------------
#
# This template gets loaded when "/news" is requested.
#
# The page first displays the most recent featured News entry, followed by the
# remaining News entries in reverse-chronological order.
-#}
@insaurabh
insaurabh / getfieldtype.php
Created July 25, 2019 06:35
#craftcms get field type in craftcms 3
<!-- In service file -->
public function getFieldType($fieldName='')
{
if ($fieldName === '') {
return null;
}
$fieldType = (new Query())
->select(['type'])
=========== Date : Jan 2019 ==========
1) Data structure, 1 problem each day on geeksforgeeks
2) Js
2.1) Event bubbling 3 examples
2.2) Webworker https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API ,3 example.
3) Play on canvas
3.1) canvas game https://github.com/maddyBoy/canvas-game-udemy
3.2) Improve the performance , https://www.html5rocks.com/en/tutorials/canvas/performance/
@insaurabh
insaurabh / preload-css-wordpress.php
Created May 10, 2019 06:49
Preload css in wordpress.
// preload css in wordpress
// add this code in child theme function.php
add_filter( 'style_loader_tag', 'preload_css', 10, 2 );
function preload_css( $html, $handle ){
$targetHanlde = array('zuhaus_mikado_child_style');
if( in_array( $handle, $targetHanlde ) ){
@insaurabh
insaurabh / index.html
Created March 20, 2019 05:59
map in js
<div id="root">Hi</div>
@insaurabh
insaurabh / twig-template.twig
Created February 28, 2019 09:30
Get entries based on custom field in twig template
{% set sponsoredentries = craft.entries({ id: 'not ' ~ entry.id })
.section(["articles", "sneakers"])
.lightswitchFieldHandle(1)
.limit(10)
%}
{% for item in sponsoredentries %}
<div class="content">
<p>{{ item.title }}</p>
@insaurabh
insaurabh / controller.php
Created February 28, 2019 06:19
Update a custom field in custom plugin controller folder and reset the required fields.
public function actionSponsoredEntriesPriority() {
$this->requireAdmin();
$this->requireAjaxRequest();
$newPriority = craft()->request->getPost('newPriority');
$entryId = craft()->request->getPost('entryId');
$success = false;
$message = Craft::t('Any message from controller');
$entries = craft()->entries;
@insaurabh
insaurabh / debug.php
Last active January 17, 2019 05:25
How to write log in wordpress from child theme.
// add in child theme function.php
// For more info : https://codex.wordpress.org/Debugging_in_WordPress
// Step 1 : define( 'WP_DEBUG', true );
// Step 2 : define( 'WP_DEBUG_LOG', true );
// Step 3 : Paste the below code in child theme function.php
// Step 4 : Call the function as : hb_write_log('lets debug');
// Step 5 : See the logs @ /website-entry-point/wp-content/debug.log ( if there is no file create a one with same name.)
if (!function_exists('hb_write_log')) {
function hb_write_log($log) {
<?php
// get the attribute
add_action( 'woocommerce_shop_loop_item_title', 'show_attribute_custom_action', 15 );
function show_attribute_custom_action() {
global $product;
$sizeAttribute = array_shift( wc_get_product_terms( $product->id, 'pa_size', array( 'fields' => 'names' ) ) );