Skip to content

Instantly share code, notes, and snippets.

@mcdevlog
mcdevlog / mysqli-object-oriented.php
Created January 28, 2019 11:13
Mysqli Object Oriented
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$city = "Amersfoort";
@mcdevlog
mcdevlog / numbersonly.js
Created March 16, 2018 06:17
Prevent typing non-numeric in input box
document.querySelector("input").addEventListener("keypress", function (evt) {
if (evt.which < 48 || evt.which > 57)
{
evt.preventDefault();
}
});
@mcdevlog
mcdevlog / date_diff.php
Created February 23, 2018 04:45
find difference between two dates
<?php
$datetime1 = strtotime('May 3, 2012 10:38:22 GMT');
$datetime2 = strtotime('06 Apr 2012 07:22:21 GMT');
$secs = $datetime2 - $datetime1;// == <seconds between the two times>
$days = $secs / 86400;
?>
@mcdevlog
mcdevlog / checkurl.js
Created February 19, 2018 11:13
get the url parameters of current page
window.location.search //get the url parameters as string
window.location.search.substr(1).split('&') //removes query mark and arrange all parameters in array
@mcdevlog
mcdevlog / lastArraykey.php
Created February 13, 2018 03:50
Get last array key
<?php
//using end() function to find last array key changes the array pointer, which can cause problems.
$array = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 2);
// Get array keys
$arrayKeys = array_keys($array);
// Fetch last array key
$lastArrayKey = array_pop($arrayKeys);
//iterate array
foreach($array as $k => $v) {
<?php
function numeric_pagination() {
global $wp_query;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
@mcdevlog
mcdevlog / custom-logo.php
Last active October 11, 2016 11:57
Adds custom logo support to wordpress theme
<?php
function wp_custom_logo(){
add_image_size('theme-logo', '160', '90');
add_theme_support('custom-logo', array(
'size' => 'theme-logo'
));
}
add_action('after_setup_theme', 'wp_custom_logo');
?>
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@mcdevlog
mcdevlog / folded corner.css
Created July 4, 2014 06:15
Folded Corner
.note:before {
content: "";
position: absolute;
top: 0;
right: 0;
border-width: 0 16px 16px 0;
border-style: solid;
border-color: #658E15 #fff;
}
@mcdevlog
mcdevlog / sticky-footer.html
Created June 23, 2014 08:59
Sticky footer by Chris Coyier