Skip to content

Instantly share code, notes, and snippets.

View mayeenulislam's full-sized avatar
🤖
AI won't replace you

Mayeenul Islam mayeenulislam

🤖
AI won't replace you
View GitHub Profile
@mayeenulislam
mayeenulislam / Connection fails fallback with PHP file read
Last active January 4, 2016 06:38
Check the latest jQuery library from the server. If fails, load the library from the local directory.
<?php
/**
* According to the lhrec_106's answer at StackOverflow
* http://stackoverflow.com/a/17339542/1743124
*/
$jQueryLatestURI = "http://code.jquery.com/jquery-latest.min.js";
@$connection = fopen( $jQueryLatestURI, "r" );
@mayeenulislam
mayeenulislam / cURL practice
Last active August 29, 2015 14:01
Grabbing a complete website usig cURL
<?php
/* Assisted by Mr. Ariful Haque */
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'http://www.oilprice.com');
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
@mayeenulislam
mayeenulislam / WP: post_is_in_descendant_category
Last active December 4, 2016 16:25
WordPress: post_is_in_descendant_category function (Source: Codex)
<?php
/**
* Tests if any of a post's assigned categories are descendants of target categories
*
* @param int|array $cats The target categories. Integer ID or array of integer IDs
* @param int|object $_post The post. Omit to test the current post in the Loop or main query
* @return bool True if at least 1 of the post's categories is a descendant of any of the target categories
* @see get_term_by() You can get a category by name or slug, then pass ID to this function
* @uses get_term_children() Passes $cats
* @uses in_category() Passes $_post (can be empty)
@mayeenulislam
mayeenulislam / WP: Force sub-categories to use the parent category template
Created May 29, 2014 06:34
WordPress: Force sub-categories to use the parent category template - werdswords.com
function new_subcategory_hierarchy() {
$category = get_queried_object();
$parent_id = $category->category_parent;
$templates = array();
if ( $parent_id == 0 ) {
// Use default values from get_category_template()
$templates[] = "category-{$category->slug}.php";
@mayeenulislam
mayeenulislam / Colorful grids
Last active August 29, 2015 14:03
Colorful grids
<script type="text/javascript">
/**
* Source: http://stackoverflow.com/a/10540361
* Thanks to: dknaack
*
* Loads custom color in each of the divs' background on each iteration
*/
function get_random_color() {
@mayeenulislam
mayeenulislam / Default Taxonomy Term for CPT
Last active April 5, 2023 11:07
Make Default taxonomy term for Custom Post Type - WordPress
/**
* Author: Michael Fields
* Source: http://wordpress.mfields.org/2010/set-default-terms-for-your-custom-taxonomies-in-wordpress-3-0/
* Thanks a lot for the nice tweak
*/
/**
* Define default terms for custom taxonomies in WordPress 3.0.1
*
@mayeenulislam
mayeenulislam / Foreach Loop from Associative Array
Last active August 29, 2015 14:05
Foreach Loop from Associative Array
<?php
// A simple foreach() loop from an array
$age_array = array(
'0-18' => '0 - 18',
'19-25' => '19 - 25',
'26-30' => '26 - 30',
'31-50' => '31 - 50',
'51-65' => '51 - 65',
@mayeenulislam
mayeenulislam / WordPress Default Widget
Created November 20, 2014 05:37
Default WordPress widgets
<div id="secondary" class="widget-area">
<ul class="xoxo">
<?php if ( is_active_sidebar('primary_widget_area') ) : ?>
<?php dynamic_sidebar('primary_widget_area'); //load widgets from Admin Panel ?>
<?php else : ?>
<?php // Load the following widgets we are assigning here ?>
<li id="default-widget-1" class="widget-container default-widgets">
@mayeenulislam
mayeenulislam / content-sidebar-sidebar.css
Created December 23, 2014 11:43
A responsive approach to 3 column layout with 2 sidebars in different formation
/* Aesthetics */
.container{
width: 100%;
max-width: 980px;
margin-left: auto;
margin-right: auto;
}
/* Debugging */
#content,
aside{
@mayeenulislam
mayeenulislam / jQuery - show or hide WP meta boxes on post type selection
Created December 24, 2014 04:59
jQuery - show/hide WP meta boxes on post type selection. To make things work, you have to assure the jQuery is turned on, and you have to enqueue the scripts using `admin_enqueue_scripts()`
jQuery(document).ready(function($) {
$('body.post-new-php #formatdiv input[id="post-format-gallery"], body.post-new-php #formatdiv input[id="post-format-video"]').change(function(){
$('.news-head-div').slideUp();
$('.news-highlight-div').slideUp();
$('#news-position').slideUp();
$('#categorydiv').slideUp();
});
$('body.post-new-php #formatdiv input[id="post-format-0"]').change(function(){