Skip to content

Instantly share code, notes, and snippets.

View senlin's full-sized avatar

Pieter Bos senlin

View GitHub Profile
@senlin
senlin / gist:1079895
Created July 13, 2011 07:45
show uploaded images on single-customposttype.php file
// use this only for the metabox script of Rilwis - http://www.deluxeblogtips.com/p/meta-box-script-for-wordpress.html#images
// the code below shows the image with a link to itself (to be used on thickbox overlays)
global $wpdb;
$meta = get_post_meta(get_the_ID(), 'sl_screenshots', false);
$meta = implode(',', $meta);
$images = $wpdb->get_col("
SELECT ID FROM $wpdb->posts
WHERE post_type = 'attachment'
@senlin
senlin / search-to-nav.php
Created October 2, 2011 23:48
add search box to navigation bar
<?php
// ADD SEARCH BOX TO NAVIGATION
function add_search_box($items, $args) {
ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();
$items .= '<li class="nav_search">' . $searchform . '</li>';
return $items;
}
@senlin
senlin / icons-social.php
Created October 29, 2011 15:21
Add Facebook, Twitter, Google+ and LinkedIn sharing to your template files with this easy to adapt tempate-part
<?php /*
Name: Social Media Icons Template Part
Description: Add Facebook, Twitter, Google+ and LinkedIn sharing to your template files with this easy to adapt tempate-part
Author: Piet Bos
Author URI: http://wpti.ps
Instructions: Step 1. Take the code from line 10-36 of this file, paste them into a blank file, save that file as icons-social.php and upload it to your theme's directory. On lines 19 and 21 you need to fill in your Twitter username and on line 24 you need to upload your favourite tweet-button (or grab it from http://a2.twimg.com/a/1319826270/images/goodies/tweetn.png) to the images folder of your theme. Step 2. Take line 39 of this file and paste it into your template files on the place where you want the icons to show up. Step 3. Take the scripts of line 42-49 and paste them in your footer.php file just above the closing </body> tag. Step 4. Style through CSS. NOTE that with the code below you will get 4 working share buttons. If you however want to make adjustments then visit the following pa
@senlin
senlin / add-breadcrumb-navigation.php
Created March 15, 2012 17:54
Add Breadcrumb Navigation
<?php // Add Breadcrumb Navigation
function write_breadcrumb() {
$pid = $post->ID;
$trail = '<a href="/">'. __('Home', 'textdomain') .'</a>';
if (is_front_page()) {
// do nothing
}
elseif (is_page()) {
$bcarray = array();
@senlin
senlin / functions.php
Created March 17, 2012 15:49
wptips_new_default_header_images for forest
<?php
//ADD NEW DEFAULT HEADER IMAGES
function wptips_new_default_header_images() {
$child2011_dir = get_bloginfo('stylesheet_directory');
register_default_headers( array (
'image1' => array (
'url' => "$child2011_dir/images/banner1.jpg",
'thumbnail_url' => "$child2011_dir/images/image1-thumb.jpg", // 230 x 66px
'description' => __( 'Image Description', 'child2011' )
) // the last image does not get a comma
@senlin
senlin / wp_nav_menu_hor.php
Created April 9, 2012 03:34
wpmlforums-location-of-flags-on-navigation-bar-post-54904
// Filter wp_nav_menu() to add additional links and other output
function new_nav_menu_items($items,$args) {
if (function_exists('icl_get_languages')) {
$languages = icl_get_languages('skip_missing=0');
if(1 < count($languages)){
foreach($languages as $l){
if(!$l['active']){
$items = $items.'<li class="menu-item"><a href="'.$l['url'].'"><img src="'.$l['country_flag_url'].'" height="12" alt="'.$l['language_code'].'" width="18" /> </a></li>';
}
}
@senlin
senlin / wpml-language-switch.php
Created April 10, 2012 00:35
wpml forum topic: display-the-language-switcher-in-the-wp-menu; show all langauges but the current one
<?php
// add the following lines to the functions.php file of your theme
function wpml_language_switch() {
$lang = icl_get_languages('skip_missing=N');
$ret = '';
if(count($lang) > 0) {
foreach($lang as $value) {
$ret .= ($value['active'] == 0) ? '<li class="language dropdown menu-item"><a href="' . $value['url'] . '">' .
$value['native_name'] . '</a></li>' : '';
}
@senlin
senlin / upto6columns.html
Created June 28, 2012 14:19
Add up to 6 columns to Basejump WordPress Theme
<p>One column full width content</p>
<div class="one-half first">Two columns full width content </div>
<div class="one-half">Two columns full width content </div>
<div class="one-third first">Three columns full width content </div>
<div class="one-third">Three columns full width content </div>
<div class="one-third">Three columns full width content </div>
<div class="one-fourth first">Four columns full width content </div>
@senlin
senlin / page_children.php
Created July 26, 2012 15:23
List children of Page with excerpt
<?php
$pageChildren = get_pages('sort_column=menu_order&hierarchical=0&child_of='.$post->ID);
if ( $pageChildren ) {
foreach ( $pageChildren as $pageChild ) {
echo '<div class="page-excerpt-wrapper">';
echo '<h2>'. $pageChild->post_title.'</h2>';
if ($pageChild->post_excerpt){
echo '<p>'.$pageChild->post_excerpt.'</p>';
}
echo '</div>';
@senlin
senlin / display-message-on-older-posts.php
Created August 13, 2012 23:36
Display a message on older posts
<?php //display a message on older posts
function older_post_message () {
$posted = get_the_time('U');
$current = current_time('timestamp');
//Convert difference in seconds to days
$diffTime = ($current - $posted) / (60*60*24);
if($diffTime > 365){
echo '<div class=older-post-message>' . __('This post was written more than a year ago and <em>might</em> not be entirely accurate anymore.', 'text-domain') . '</div><br />';
}
}