Skip to content

Instantly share code, notes, and snippets.

View sureshkldh's full-sized avatar
🏠
Working from Office

sureshkldh

🏠
Working from Office
View GitHub Profile
<?php
$apiKey=array('dc394775', 'dc394775');
$random_keys=array_rand($apiKey);
$keys = 'tt3766394,tt0064418,tt2378794';
$key = explode(',', $keys);
foreach($key as $key)
{
@sureshkldh
sureshkldh / Deleting all files from a folder using PHP
Created November 1, 2019 05:38
Deleting all files from a folder using PHP
<?php
// PHP program to delete all
// file from a folder
// Folder path to be flushed
$folder_path = "file";
// List of name of files inside
// specified folder
$files = glob($folder_path.'/*');
@sureshkldh
sureshkldh / omdbapi with cache
Last active October 31, 2019 12:04
omdbapi with cache
<?php
$url = $_SERVER["SCRIPT_NAME"];
$page = $_GET['page'] ='' ? '' : $_GET['page'];
$search = $_GET['s'] ='' ? '' : $_GET['s'];
$search = str_replace(' ', '', $search).''.$page;
$break = Explode('/', $url);
$file = $break[count($break) - 1];
$cachefile = 'cache/cached-'.$search.'-'.substr_replace($file ,"",-4).'.html';
$cachetime = 18000;
<?php
$a=array("red","green","blue","yellow","brown");
$random_keys=array_rand($a);
echo $a[$random_keys];
if (isset($_GET['page'])) {
$pageno = $_GET['page'];
} else {
@sureshkldh
sureshkldh / Example for custom pagination in php
Created October 31, 2019 06:52
Example for custom pagination in php
<?php
// Example for custom pagination in php
$total_rows = 554;
$no_of_records_per_page = 10;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$url = "https://gist.github.com/"
@sureshkldh
sureshkldh / Stop Custom post for guestes
Created December 15, 2018 09:55
Stop Custom post for guestes
function tp_stop_guestes( $content ) {
global $post;
if ( $post->post_type == 'post' ) {
if ( !is_user_logged_in() ) {
$content = 'Please login to view this post';
wp_redirect(get_the_permalink(5));
}
}
@sureshkldh
sureshkldh / Woocommerce product listing without pagination
Created March 24, 2018 05:43
Woocommerce product listing without pagination
/************** Woocommerce product listing without pagination ************************/
add_action( 'pre_get_posts', 'custom_pre_get_posts' );
function custom_pre_get_posts($query) {
if ( is_woocommerce() ) {
$query->set('posts_per_page', -1);
}
return $query;
}
@sureshkldh
sureshkldh / get_time_zone
Created March 21, 2018 12:43
get_time_zone
function get_time_zone() {
$ip = $_SERVER['REMOTE_ADDR'];
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => "http://www.geoplugin.net/json.gp?ip=".$ip,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => false
@sureshkldh
sureshkldh / custom links in wordpress
Created February 28, 2018 11:59
custom links in wordpress
@sureshkldh
sureshkldh / Load more Ajax
Created February 8, 2018 12:37
Load more Ajax
<?php
/**
* Template Name: Load more
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
* @package WordPress
* @subpackage Twenty_Fifteen