Skip to content

Instantly share code, notes, and snippets.

View borantula's full-sized avatar

Bora Yalcin borantula

View GitHub Profile
@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 / 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 / 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 / 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();