Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
ChrisLTD / Drupal6 - Show block on Taxonomy term listings
Created April 14, 2011 02:49
Show block on Taxonomy term listings if it is inside a particular vocabular
<?php
// Show block on Taxonomy term listings
$make_block_visible = FALSE;
$vocab_id_to_trigger_show_block = 8;
if ((arg(0) == 'taxonomy') && (arg(1) == 'term')) {
$term_obj = taxonomy_get_term(arg(2));
$vocab_id = $term_obj->vid;
if($vocab_id == $vocab_id_to_trigger_show_block){
$make_block_visible = TRUE;
}
@ChrisLTD
ChrisLTD / gist:919955
Created April 14, 2011 17:13
Read a two column CSV file and output it into an html file
require 'csv'
htmlfile = File.new "output.html", "w"
csvfile = CSV.read "input.csv"
csvfile.each do |x,y|
htmlfile.puts "<h1>#{x}</h1>\n<p>#{y}</p>\n\n"
end
@ChrisLTD
ChrisLTD / gist:957014
Created May 5, 2011 13:28
Django Nested Regroup Example (Group by category foreign key, then month of start date)
#views.py
def events_index(request, year):
selected_year = Year.objects.get(title=year)
events_list = Event.objects.filter(year = selected_year.id).order_by('category','start_date')
return render_to_response('events_list.html', {"events_list": events_list})
#events_list.html
{% regroup events_list by category.title as events_list_by_category %}
@ChrisLTD
ChrisLTD / gist:988796
Created May 24, 2011 14:25 — forked from anonymous/gist:988792
Add Custom CSS to MCE Editor
add_filter('mce_css', 'my_editor_style');
function my_editor_style($url) {
if ( !empty($url) )
$url .= ',';
// Change the path here if using sub-directory
$url .= trailingslashit( get_stylesheet_directory_uri() ) . 'editor-style.css';
return $url;
@ChrisLTD
ChrisLTD / functions.php
Created May 24, 2011 14:27
Modify TinyMCE in Wordpress to exclude buttons
/*
* Modifying TinyMCE editor to remove unused items.
*/
function customformatTinyMCE($init) {
// Add block format elements you want to show in dropdown
$init['theme_advanced_blockformats'] = 'p,h1,h2,h3,h4,h5,h6,div';
$init['theme_advanced_disable'] = 'justifyfull,pasteword';
$init['theme_advanced_buttons2_add'] = 'styleselect';
$init['theme_advanced_styles'] = 'Align Right=alignright, Align Left=alignleft';
@ChrisLTD
ChrisLTD / functions.php
Created May 24, 2011 14:54
Enable Kitchen Sink in Wordpress TinyMCE by default
function unhide_kitchensink( $args ) {
$args['wordpress_adv_hidden'] = false;
return $args;
}
add_filter( 'tiny_mce_before_init', 'unhide_kitchensink' );
@ChrisLTD
ChrisLTD / functions.php
Created July 22, 2011 17:11
Create Wordpress widget that outputs shortcode
<?
function sidebarbrief_func($atts) {
extract(shortcode_atts(array('foo' => 'something'), $atts));
global $more; // Declare global $more (before the loop).
$posts_query = new WP_Query( array( 'post_type' => array('brief'), 'tag_id' => 16, posts_per_page => 1 ) );
$output = '<h1>News in Brief</h1>';
while ( $posts_query->have_posts() ) : $posts_query->the_post();
$more = 0; // Set (inside the loop) to display content above the more tag.
$output .= '<div class="brief">';
@ChrisLTD
ChrisLTD / 1-tablemarkup.html
Created April 26, 2012 14:37 — forked from paulirish/1-tablemarkup.html
whitespace use for html/css readability
<!-- formatting fun #1: tables! -->
<!-- use whitespace to mimic the layout you want. leave off optional end tags for readability -->
<table>
<caption>Selector engines, parse direction</caption>
<thead>
<tr><th>Left to right <th>Right to left
<tbody>
<tr><td>Mootools <td>Sizzle
@ChrisLTD
ChrisLTD / WordpressTimeline.php
Created August 21, 2012 18:21
Wordpress Timeline using custom content type
<?php
// 1. Put all timeline entries into array
$timeline_entries = array();
// Retrieve entries sorted by date
$query = new WP_Query( array('post_type' => 'timeline-entry', 'posts_per_page' => -1, 'order' => 'ASC' , 'orderby' => 'meta_value', 'meta_key' => 'date' ));
if ($query->have_posts()):
while ( $query->have_posts() ):
$query->the_post();
$date = get_custom_field('date');
@ChrisLTD
ChrisLTD / gist:3924562
Created October 20, 2012 19:56
Drupal 7 image gallery output
// Requires Content Type with image field with multiple images as described here: http://drupal.stackexchange.com/a/5901
// Title is output as caption if there is title text
// Image size is determined by custom image style in Drupal admin named "gallery_thumb"
<?php
$gallery_images = $node->field_gallery_image['und'];
for($i = 0; $i < count($gallery_images); $i++) {
$image = $gallery_images[$i];
$output = '<a href="' . file_create_url($image['uri']) . '">';
$output .= '<img src="' . image_style_url("gallery_thumb", $image['uri']) . '">';