Skip to content

Instantly share code, notes, and snippets.

James Nodws Nodws

Block or report user

Report or block Nodws

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View json
<?
$id = $_SERVER['QUERY_STRING']; //$_GET[id];
$json = '[
{"title":"trench", "img":"https://i.imgur.com/HoPQJqI.jpg"},
{"title":"coat"}
]';
$mydata = json_decode($json);
foreach ($mydata as $v):
if ($v->title == $id) {
$item = $v->title;
View Migration.sql
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
View Cache
<?php
$cache = 'data.txt';
if(date("Ymd", filemtime($cache)) < date("Ymd") || filesize($cache) < 1):
$data = get_data(); // do your thing
$file = fopen($cache,'w+');
$text = is_array($data) ? json_encode($data) : $data;
fwrite($file, $text);
fclose($file);
else:
$file = fopen($cache,'w+');
View Center hero image
.hero{
height:200px;
overflow:hidden;
display:flex;
align-items:center;
justify-content:center
}
.hero div{
min-width:100%; display:flex;
View Truncate text by word.php
<?php
function texto($text, $limit=8) {
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
}
return $text;
}
@Nodws
Nodws / .htaccess
Last active Nov 29, 2018
Htaccess snips
View .htaccess
<FilesMatch "^(wp-config|wp-settings|wp-trackback|wp-comments-post|xmlrpc)\.php$">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
View Breadcrumbs.php
<?php
//FOR POST
$t = wp_get_post_terms(get_the_id(),'taxonomy');
$t[0] = ($t[0]->parent && !$t[1]->parent) ? $t[0] : $t[1];
if($t[0]->parent)
{ $p = get_term_by('id',$t[0]->parent,'taxonomy');
echo '<a href="'.get_term_link($t[0]->parent,'taxonomy').'">'.$p->name.'</a> &raquo; '; }
echo '<a href="'.get_term_link($t[0]->term_id,'taxonomy').'" class="crumb-current">'.$t[0]->name.'</a>';
//FOR ARCHIVE
@Nodws
Nodws / WPConfig
Last active Feb 11, 2019
home and theme dirs
View WPConfig
define('td', get_bloginfo('template_directory').'/' );
define('hd', esc_url(home_url( '/' )));
//WPconfig
$path = ''; //No trail
$http = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
define( 'WP_SITEURL', $http . $_SERVER['SERVER_NAME'] . $path );
define( 'WP_HOME', $http . $_SERVER['HTTP_HOST'] . $path );
define('DB_NAME', $_SERVER['RDS_DB_NAME']);
@Nodws
Nodws / Urlmask
Last active Aug 29, 2015
URL masking
View Urlmask
<body style="padding:0; margin:0;height:100%;overflow:hidden"><iframe src="http://nodws.com" style="height: 100%;width:100% " allowtransparency="true" frameborder="0"></iframe></body>
View Partial page refresh
setInterval(function() {
$("#refresh").load(location.href+" #refresh>*","");
}, 10000); // milliseconds to wait
You can’t perform that action at this time.