Skip to content

Instantly share code, notes, and snippets.

View CodeNegar's full-sized avatar

CodeNegar CodeNegar

View GitHub Profile
@CodeNegar
CodeNegar / composer.json
Last active April 9, 2017 17:08
Composer basic start point strcuture
{
"name": "vendor-name/project-name",
"authors": [
{
"name": "Xavier Lacot",
"email": "[email protected]",
"homepage": "http://www.lacot.org",
"role": "Developer"
}
],
@CodeNegar
CodeNegar / gist:abc998db76d628583b6e
Last active August 29, 2015 14:19
Get views count
<?php
echo getPostViews(get_the_ID());
?>
@CodeNegar
CodeNegar / gist:df0ba903081c2e153106
Last active August 29, 2015 14:19
set post views
<?php
setPostViews(get_the_ID());
?>
<?php
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count.' Views';
{
"word_separators": "./\\()\"'-:,.;<>~!@#%^&*|+=[]{}`~?"
}
// Get The Page ID You Need
get_option( 'woocommerce_shop_page_id' );
get_option( 'woocommerce_cart_page_id' );
get_option( 'woocommerce_checkout_page_id' );
get_option( 'woocommerce_pay_page_id' );
get_option( 'woocommerce_thanks_page_id' );
get_option( 'woocommerce_myaccount_page_id' );
get_option( 'woocommerce_edit_address_page_id' );
get_option( 'woocommerce_view_order_page_id' );
get_option( 'woocommerce_terms_page_id' );
/*
* goes in theme functions.php or a custom plugin
**/
// add item to cart on visit
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 64;
$found = false;
(function($) {
$(document).ready(function() {
$(function() {
});
});
})(jQuery);
@CodeNegar
CodeNegar / gist:4051123
Created November 10, 2012 13:48
PHP: Wordpress navigation menu
<?php
// functions.php
add_theme_support('menus');
function reg_menu() {
register_nav_menus(
array(
'head-menu' => __('Head Menu')
)
);
}
@CodeNegar
CodeNegar / gist:4030888
Created November 7, 2012 11:07
PHP: Wordpress last blog update jdate
<?php
function last_update() {
global $wpdb;
$date = $wpdb->get_var("SELECT DISTINCT post_date FROM $wpdb->posts WHERE post_date < '".current_time('mysql')."' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
return jdate('l d M Y', strtotime($date));
}
?>