Skip to content

Instantly share code, notes, and snippets.

@chillbits-legacy
chillbits-legacy / sub-menu-mobile.js
Created November 22, 2016 09:18
Sub-menu jquery on mobile
$(".footer-mobile-menu li#submenu-mn").click(function(){
if ($(".bottom-mobmenu-container").hasClass("expanded")) {
$(".bottom-mobmenu-container.expanded").removeClass("expanded").slideUp(350);
$(this).removeClass("openz");
} else {
$(".bottom-mobmenu-container").addClass("expanded").slideDown(350);
$(this).addClass("openz");
}
});
$("#bottom-menu-mobile > li.menu-item-has-children").click(function(){
@chillbits-legacy
chillbits-legacy / wp-menu.sql
Created November 18, 2016 07:31
How menu stored in database
/*
Menu by itself is a taxonomy in WP. It means that you can find all menus in wp_terms table, by running following query:
*/
SELECT *
FROM wp_terms AS t
LEFT JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
WHERE tt.taxonomy = 'nav_menu';
/*
Menu item is custom post type in WP. They are stored in wp_posts table. You can find all of them by using this query:
@chillbits-legacy
chillbits-legacy / wp-config.php
Created November 17, 2016 10:53
Make wordpress install can use a same database
<?php
define('VA_REQUEST_URL', ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', VA_REQUEST_URL);
define('WP_HOME', VA_REQUEST_URL);
?>
@chillbits-legacy
chillbits-legacy / install-wp-cli.sh
Created November 17, 2016 10:45
Install wp-cli
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
@chillbits-legacy
chillbits-legacy / .htaccess
Created November 10, 2016 07:41
Wordpress .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
"main.js": {
"files": [
"scripts/test-1.js", // đặt lên trước thì nó sẽ load trước.
"scripts/main.js",
"scripts/test-2.js" // đặt sau thì nó sẽ load sau.
],
"main": true
},
@chillbits-legacy
chillbits-legacy / manifest.json
Created November 10, 2016 05:32
Config js in manifest.json file
"main.js": {
"files": [
"scripts/main.js"
],
"main": true
},
@chillbits-legacy
chillbits-legacy / category-sidebar-in-single.php
Created November 10, 2016 05:18
Display different sidebar based on category of single post
<?php
if(is_single()) {
$categories = new WPSEO_Primary_Term('category', get_the_ID());
$category_id = $categories->get_primary_term();
$category = &get_category($category_id);
switch($category->slug) {
case 'blog':
/** Viet Artisans fixes **/
// Dynamic menu activation
var vaj = jQuery.noConflict();
vaj(document).ready(function(){
currentURL = document.location.href;
vaj('.accordion-header a').each(function(index){
if(vaj(this).attr('href') == currentURL)
{
activeSideMenu(vaj(this));
return;
@chillbits-legacy
chillbits-legacy / countrycode.php
Last active July 15, 2016 08:16
Get country code from phone number
<?php
function getCountryCode($phoneNumber) {
// get your list of country codes
$countries = getCountries();
$countries = array(array("US","1","US (+1)"),array("GB","44","GB (+44)")) + $countries;
foreach( $countries as $country )
{
if ( substr( $phoneNumber, 0, strlen( '+'.$country[1] ) ) == '+'.$country[1] )
{
// match