Make WordPress Core

Ticket #23001: functions.php

File functions.php, 5.4 KB (added by gcrumb, 14 years ago)
Line 
1<?php
2
3// Theme Features Init
4
5
6add_action('after_setup_theme', 'pipp_theme_setup');
7
8function pipp_theme_setup() {
9
10 $wp_ver = get_bloginfo('version');
11
12 // Add default posts and comments RSS feed links to head
13 add_theme_support('automatic-feed-links');
14
15 // This theme uses wp_nav_menu() in one location.
16 register_nav_menus( array(
17 'top_nav' => 'Top Navigation',
18 ) );
19
20 function rok_theme_page_menu_link($item) {
21 $item = str_replace('current_page_item', 'current_page_item active', $item);
22 return $item;
23 }
24
25 add_filter('nav_menu_css_class', 'rok_theme_page_menu_link');
26
27 function rok_theme_page_menu_a_class($output) {
28 $output = str_replace('<a', '<a class="link"', $output);
29 return $output;
30 }
31
32 add_filter('walker_nav_menu_start_el', 'rok_theme_page_menu_a_class');
33}
34
35// Menu backwards compatibility
36
37function rok_old_menu() {
38
39 wp_page_menu('menu_class=horiz-menu-top&title_li=&show_home=1&link_before=<span>&link_after=</span>');
40
41}
42
43if ( function_exists('register_sidebars') )
44 register_sidebars(1, array(
45 'name' => 'Over Main Menu',
46 'before_widget' => '<div class="side-module '.get_option('mixx_over_main_widget').' rokmodtools-%1$s widgets"><div class="side-mod"><div class="side-mod2"><div class="side-title-container">',
47 'after_widget' => '</div></div></div><div class="side-mod-bottom"><div class="side-mod-bottom2"><div class="side-mod-bottom3"></div></div></div></div>',
48 'before_title' => '<h3 class="module-title"><span class="bg"><span class="bg2">',
49 'after_title' => '</span></span></h3></div><div class="module">',
50 ));
51
52
53function pipp_gallery_shortcode($attr) {
54 global $post;
55
56 static $instance = 0;
57 $instance++;
58
59 // Allow plugins/themes to override the default gallery template.
60 $output = apply_filters('post_gallery', '', $attr);
61 if ( $output != '' )
62 return $output;
63
64 // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
65 if ( isset( $attr['orderby'] ) ) {
66 $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
67 if ( !$attr['orderby'] )
68 unset( $attr['orderby'] );
69 }
70
71 extract(shortcode_atts(array(
72 'order' => 'ASC',
73 'orderby' => 'menu_order ID',
74 'id' => $post->ID,
75 'itemtag' => 'dl',
76 'icontag' => 'dt',
77 'captiontag' => 'dd',
78 'columns' => 1,
79 'size' => 'full',
80 'include' => '',
81 'exclude' => ''
82 ), $attr));
83
84 $id = intval($id);
85 if ( 'RAND' == $order )
86 $orderby = 'none';
87
88 if ( !empty($include) ) {
89 $include = preg_replace( '/[^0-9,]+/', '', $include );
90 $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
91
92 $attachments = array();
93 foreach ( $_attachments as $key => $val ) {
94 $attachments[$val->ID] = $_attachments[$key];
95 }
96 } elseif ( !empty($exclude) ) {
97 $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
98 $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
99 } else {
100 $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
101 }
102
103 if ( empty($attachments) )
104 return '';
105
106 if ( is_feed() ) {
107 $output = "\n";
108 foreach ( $attachments as $att_id => $attachment )
109 $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
110 return $output;
111 }
112
113 $itemtag = tag_escape($itemtag);
114 $captiontag = tag_escape($captiontag);
115 $columns = intval($columns);
116 $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
117 $float = is_rtl() ? 'right' : 'left';
118
119 $selector = "gallery-{$instance}";
120
121 $gallery_style = $gallery_div = '';
122 if ( apply_filters( 'use_default_gallery_style', true ) )
123 $gallery_style = "
124 <style type='text/css'>
125 #{$selector} {
126 margin: auto;
127 }
128 #{$selector} .gallery-item {
129 float: {$float};
130 margin-top: 10px;
131 text-align: center;
132 width: {$itemwidth}%;
133 }
134 #{$selector} img {
135 border: 2px solid #cfcfcf;
136 }
137 #{$selector} .gallery-caption {
138 margin-left: 0;
139 }
140 </style>
141 <!-- see gallery_shortcode() in wp-includes/media.php -->";
142 $size_class = sanitize_html_class( $size );
143 $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
144 $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
145
146 $i = 0;
147 foreach ( $attachments as $id => $attachment ) {
148 $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
149
150 $output .= "<{$itemtag} class='gallery-item'>";
151 $output .= "
152 <{$icontag} class='gallery-icon'>
153 $link
154 </{$icontag}>";
155 if ( $captiontag && trim($attachment->post_excerpt) ) {
156 $output .= "
157 <{$captiontag} class='wp-caption-text gallery-caption'>
158 " . wptexturize($attachment->post_excerpt) . "
159 </{$captiontag}>";
160 }
161 $output .= "</{$itemtag}>";
162 if ( $columns > 0 && ++$i % $columns == 0 )
163 $output .= '<br style="clear: both" />';
164 }
165
166 $output .= "
167 <br style='clear: both;' />
168 </div>\n";
169
170 return $output;
171}
172
173//add_filter('post_gallery', 'pipp_gallery_shortcode', 4,1 );
174
175?>