you are here: codestackercodes [RSS]

disable post revisions

in your /wp-config.php


define('WP_POST_REVISIONS', false);


delete post revisions

DELETE a,b,c  
FROM wp_posts a  
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)  
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)  
WHERE a.post_type = 'revision'

page x of y in wordpress

based on


// paste in functions.php

function pagination($pages = '', $range = 4){
     $showitems = ($range * 2)+1;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '') {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages) {
             $pages = 1;

     if(1 != $pages) {
         echo "Page ".$paged." of ".$pages;



// in your template 

if (function_exists("pagination")) { pagination($additional_loop->max_num_pages); } 


embed youtube using html5


<iframe class="youtube-player" type="text/html" width="640" height="385" src="" frameborder="0">


Got it! Thanks a lot again for hepilng me out!

Got it! Thanks a lot again for hepilng me out!

wordpress $post variables

$post–>ID # ID of the current post.
$post–>post_category # Retrieves the ID of the post category.
$post–>post_parent # ID of the page parent. Useful for creating custom navigational elements.
$post–>post_title # Post Title
$post–>post_excerpt # Post excerpt
$post–>post_content # Retrieves all of the post content, along with any markup.
$post–>post_name # Retrieving the slug of a post.
$post–>guid # Post Url
$post–>post_author # ID of post author post_parent
$post–>post_type # Returns the type, page or post.
$post–>menu_order # Returns the menu order as set in the post/page editing window. Often menu items are sorted via this value.
$post–>post_date # Retrieves the integer timestamp for when the post was published. The output can be customized. See the date manual.
$post–>post_modified # Retrieves the integer timestamp for when the post was last modified.
$post–>post_status # Retrieves one of five possible posts statuses: publish, private, draft, pending, future.
$post–>comment_count # Returns the number of comments, pings, and trackbacks for a given post.

remove wordpress 3.1 admin bar

paste in functions.php


grep an object's available methods

Object.methods.grep /inspect/
=> ["inspect", "pretty_inspect", "pretty_print_inspect"]

return the url base in ruby

>> url = ""
>> url[/https?:\/\/.[^\/]+/]
=> ""

clean wordpress gallery css

paste in your functions.php and get these elements:

.gallery {}
.gallery-item {}
.gallery-icon {}
.gallery-caption {}


function remove_gallery_style() {
  return "<div class='gallery'>";
add_filter('gallery_style', 'remove_gallery_style');


placeholder attribute for inputs in IE

require jquery and modernizer

		if($(this).val()=="" && $(this).attr("placeholder")!=""){
				if($(this).val()==$(this).attr("placeholder")) $(this).val("");
				if($(this).val()=="") $(this).val($(this).attr("placeholder"));

open all externals links in a new window

        if ( != {
                $(this).attr('target', '_new');

activerecord without rails

require 'active_record'

ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :host => 'localhost', :user => 'root', :password => 'mypass', :database => 'mydatabase')

class User < ActiveRecord::Base ; end

puts User.count
#=> 9

writing a file

r - Open a file for reading. The file must exist.
w - Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
a - Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist.
r+ - Open a file for update both reading and writing. The file must exist.
w+ - Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
a+ - Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.

doc = "hello world", 'w') {|f| f.write(doc) }

hide address bar in safari mobile

this code lets you hide the address bar in safari mobile. your webapp will look like a native one.

<body onload="window.scrollTo(0, 1)">

[css3] link animation

a {     
	color: #fff;
	-webkit-transition: color .5s ease-in;  
	-moz-transition: color .5s ease-in;  
	-o-transition: color .5s ease-in;  
	transition: color .5s ease-in;  

a:hover {
	color: #ccc;     

[css3] fade in page

@-webkit-keyframes fade-in {
	0%   { opacity: 0; }
	50%   { opacity: 0; }
	100% { opacity: 1; }

body {
	-webkit-animation-name: fade-in;
	-webkit-animation-duration: 1.5s;

check avaliability

# controller

def check_availability
  render :update do |page|
    if User.find(:first, :conditions => { :login => params[:user][:login] })
      page[:login_instant_feedback].replace_html 'Not available'

# view

link_to_remote 'check availability', { :url => { :action => 'check_availability' }, :before => $('login_instant_feedback').update('checking...'); new Effect.Appear('login_instant_feedback');" }

my .irbrc file

gems = %w(rubygems irb/completion wirble hirb ap)

gems.each do |gem_name|
    require gem_name
  rescue LoadError => e
    puts e.message

Wirble.init if Wirble #

Wirble.colorize if Wirble
Hirb.enable if Hirb # display items in a table

# Based on

# Display methods in columns

def colputs(array)
  def num_columns; 4; end

  def col_width; 25; end

  def force_length(x)
    x = x.to_s
    max_length = col_width+2
    if x.length > max_length
      x = x[0..max_length-4] + '...'
    x += (' '*max_length)

  def get_element(array, i) # displays in column order instead of row order

    num_rows = (array.length/num_columns)+1
    col = i % num_columns
    row = i / num_columns
  for i in (0..array.length)
    print force_length(get_element(array, i))
    print "  "
    puts if (i % num_columns) == (num_columns-1)

class Object
  # Return only the methods not present on basic objects in columns

  def show_methods
    colputs (self.methods -

  # Based on  

  # Display methods added by user

  def local_methods(obj = self)
    (obj.methods - obj.class.superclass.instance_methods).sort
  # Print documentation

  #   ri 'Array#pop'

  #   Array.ri

  #   Array.ri :pop

  #   arr.ri :pop

  def ri(method = nil)
    unless method && method =~ /^[A-Z]/ # if class isn't specified

      klass = self.kind_of?(Class) ? name :
      method = [klass, method].compact.join('#')
    system 'ri', method.to_s
  # Copy

  def copy(obj = self)
    system %{echo '#{obj.to_s.gsub "'", "\\'"}' | pbcopy}

wordpress categories dropdown

<!-- old way -->
<?php wp_list_categories('orderby=name&exclude=1&title_li='); ?>

<!-- dropdown -->
<select onchange='document.location.href=this.options[this.selectedIndex].value;'>
	<option><?php echo attribute_escape(__('Select Month')); ?></option>
<?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?>
Displaying Code 61 - 80 of 301 in total