Skip to content

Instantly share code, notes, and snippets.

View borantula's full-sized avatar

Bora Yalcin borantula

View GitHub Profile
@borantula
borantula / someproducts.php
Created December 12, 2013 11:22
Laravel 4 Eloquent Random Order. I always tend to forget it :)
<?php
//get 10 random products
$someProducts = Product::orderBy(DB::raw('RAND()'))->limit(10)->get();
@borantula
borantula / change.php
Created March 5, 2014 11:31
Wordpress Rewrite Rules Change
<?php
add_action('init','rewriteRules');
add_filter('post_type_link', 'portfolioPermalinks', 10, 3);
function rewriteRules()
{
// Register custom rewrite rules for portfolio post type
global $wp_rewrite;
$wp_rewrite->add_rewrite_tag('%portfolio%', '([^/]+)', 'portfolio=');
@borantula
borantula / get_oembed.php
Created June 17, 2014 09:22
WordPress Oembed Html from Url
<?php
function getOembedHtml($url,$width,$height)
{
require_once( ABSPATH . WPINC . '/class-oembed.php' );
$oembed = _wp_oembed_get_object();
$html = $oembed->get_html($url,array('width' => (int)$width,'height' => (int)$height) );
return $html;
@borantula
borantula / CalendarBase.php
Last active August 29, 2015 14:03
Base Class for Making A Calendar in PHP
<?php
//if you use it in a namespace, you'll need this line
//use \DateTime as DateTime;
//TODO: needs documentation and testing
/**
* Takes month and year, returns days of the month, next and prev month etc
* its used like $calendar = new CalendarBase(8,2014);
@borantula
borantula / gitclearcache.sh
Created August 7, 2014 07:18
Git clear cache
git rm -r --cached .
git add --all
git commit -am 'git cache cleared'
@borantula
borantula / turkish-lowercase-uppercase.js
Created October 5, 2014 14:02
Turkish case conversion in JavaScript
//source: http://stackoverflow.com/questions/1850232/turkish-case-conversion-in-javascript
String.prototype.turkishToUpper = function(){
var string = this;
var letters = { "i": "İ", "ş": "Ş", "ğ": "Ğ", "ü": "Ü", "ö": "Ö", "ç": "Ç", "ı": "I" };
string = string.replace(/(([iışğüçö]))+/g, function(letter){ return letters[letter]; })
return string.toUpperCase();
}
String.prototype.turkishToLower = function(){
@borantula
borantula / bootstrap-modal-control.js
Created August 3, 2015 09:46
Bootstrap Modal Control Class for easy usage
BootstrapModalControl = {
init : function(){
//for necessary binding
},
modelBox : function(){
//this could be dynamic if you have more than one modal
return $('#admin-modal');
},
@borantula
borantula / single.php
Created August 10, 2015 13:33
WordPress links for previous and next post
<div class="entry__arrows visible-md visible-lg">
<a class="entry__arrow entry__arrow--prev" href="<?=get_permalink(get_adjacent_post(false,'',false));?>"></a>
<a class="entry__arrow entry__arrow--next" href="<?=get_permalink(get_adjacent_post(false,'',true));?>"></a>
</div>
@borantula
borantula / gist:5589153b2a235d8ea79f
Last active September 21, 2015 12:48
Bootstrap Pagination for WordPress
function wp_bootstrap_pagination( $wp_query = false ) {
if($wp_query == false) {
global $wp_query;
}
$big = 999999999;
$pages = paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?page=%#%',
'current' => max(1, get_query_var('paged')),
@borantula
borantula / .gitignore
Created October 13, 2015 09:54
WordPress gitignore
.htaccess
wp-config.php
wp-content/uploads/
wp-cli.yml
wp-content/blogs.dir/
wp-content/upgrade/
wp-content/backup-db/
wp-content/backupwordpress*
wp-content/advanced-cache.php
wp-content/wp-cache-config.php