-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
executable file
·221 lines (202 loc) · 7.71 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
//Create Custom Postype
add_action('init', 'create_portfolio');
function create_portfolio() {
$portfolio_args = array(
'label' => __('Portfolio'),
'singular_label' => __('Portfolio'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => false,
'query_vars'=>false,
'supports' => array('title', 'editor', 'custom-fields', 'comments'),
'taxonomies' => array('category', 'post_tag')
);
register_post_type('portfolio',$portfolio_args);
register_taxonomy_for_object_type( 'category', 'portfolio');
}
//Add Portfolio Image field to Custom Post Type
add_action("admin_init", "add_portfolio");
add_action('save_post', 'update_project_image');
function add_portfolio(){
add_meta_box("portfolio_details", "Portfolio Options", "portfolio_options", "portfolio", "normal", "low");
}
function portfolio_options(){
global $post;
$custom = get_post_custom($post->ID);
$project_image = $custom["project_image"][0];
?>
<div id="portfolio-options">
<label>Project Image:</label><input name="project_image" value="<?php echo $project_image; ?>" />
</div>
<?php
}
function update_project_image(){
global $post;
update_post_meta($post->ID, "project_image", $_POST["project_image"]);
}
add_action("manage_posts_custom_column", "portfolio_columns_display");
// Add info to Custom Post Type List
function portfolio_edit_columns($portfolio_columns){
$portfolio_columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => "Project Title",
"description" => "Description",
);
return $portfolio_columns;
}
function portfolio_columns_display($portfolio_columns){
switch ($portfolio_columns)
{
case "description":
the_excerpt();
break;
}
}
//Change URL structure
// FOF Htaccess rewrite..........................
function add_query_vars($aVars) {
$aVars[] = "port_cat";
$aVars[] = "port_cat1";
// represents the name of the product category as shown in the URL
return $aVars;
}
// hook add_query_vars function into query_vars
global $wp_rewrite;
$portfolio_structure = '/portfolio/%year%/%monthnum%/%portfolio%';
$wp_rewrite->add_rewrite_tag("%portfolio%", '([^/]+)', "portfolio=");
$wp_rewrite->add_permastruct('portfolio', $portfolio_structure, false);
function photo_details_vars(){
add_rewrite_rule('^portfolio/topic/([^/]+)/page/([^/]+)/?$','index.php?page_id=1257&port_cat=$matches[1]&paged=$matches[2]','top');
add_rewrite_rule('^portfolio/topic/([^/]+)/?$','index.php?page_id=1257&port_cat=$matches[1]','top');
add_rewrite_rule('^resources/topic/([^/]+)/page/([^/]+)/?$','index.php?page_id=1284&port_cat1=$matches[1]&paged=$matches[2]','top');
add_rewrite_rule('^resources/topic/([^/]+)/?$','index.php?page_id=1284&port_cat1=$matches[1]','top');
}
add_action('init', 'photo_details_vars');
add_filter('query_vars', 'add_query_vars');
add_filter('init', 'flush_rules');
function flush_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
// Add filter to plugin init function
add_filter('post_type_link', 'portfolio_permalink', 10, 3);
// Adapted from get_permalink function in wp-includes/link-template.php
function portfolio_permalink($permalink, $post_id, $leavename) {
$post = get_post($post_id);
$rewritecode = array(
'%year%',
'%monthnum%',
'%day%',
'%hour%',
'%minute%',
'%second%',
$leavename? '' : '%postname%',
'%post_id%',
'%category%',
'%author%',
$leavename? '' : '%pagename%',
);
if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
$unixtime = strtotime($post->post_date);
$category = '';
if ( strpos($permalink, '%category%') !== false ) {
$cats = get_the_category($post->ID);
if ( $cats ) {
usort($cats, '_usort_terms_by_ID'); // order by ID
$category = $cats[0]->slug;
if ( $parent = $cats[0]->parent )
$category = get_category_parents($parent, false, '/', true) . $category;
}
// show default category in permalinks, without
// having to assign it explicitly
if ( empty($category) ) {
$default_category = get_category( get_option( 'default_category' ) );
$category = is_wp_error( $default_category ) ? '' : $default_category->slug;
}
}
$author = '';
if ( strpos($permalink, '%author%') !== false ) {
$authordata = get_userdata($post->post_author);
$author = $authordata->user_nicename;
}
$date = explode(" ",date('Y m d H i s', $unixtime));
$rewritereplace =
array(
$date[0],
$date[1],
$date[2],
$date[3],
$date[4],
$date[5],
$post->post_name,
$post->ID,
$category,
$author,
$post->post_name,
);
$permalink = str_replace($rewritecode, $rewritereplace, $permalink);
} else { // if they're not using the fancy permalink option
}
return $permalink;
}
//Shorten Title for Home Page Posts
function short_title() {
$title = get_the_title();
$count = strlen($title);
if ($count >= 38) {
$title = substr($title, 0, 38);
$title .= '…';
}
echo $title;
}
//Rewrite Excerpts
function new_excerpt_more($more) {return '…';}
add_filter('excerpt_more', 'new_excerpt_more');
// Add custom taxonomies and custom post types counts to dashboard
add_action( 'right_now_content_table_end', 'my_add_counts_to_dashboard' );
function my_add_counts_to_dashboard() {
// Custom taxonomies counts
$taxonomies = get_taxonomies( array( '_builtin' => false ), 'objects' );
foreach ( $taxonomies as $taxonomy ) {
$num_terms = wp_count_terms( $taxonomy->name );
$num = number_format_i18n( $num_terms );
$text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name, $num_terms );
$associated_post_type = $taxonomy->object_type;
if ( current_user_can( 'manage_categories' ) ) {
$num = '<a href="edit-tags.php?taxonomy=' . $taxonomy->name . '&post_type=' . $associated_post_type[0] . '">' . $num . '</a>';
$text = '<a href="edit-tags.php?taxonomy=' . $taxonomy->name . '&post_type=' . $associated_post_type[0] . '">' . $text . '</a>';
}
echo '<td class="first b b-' . $taxonomy->name . 's">' . $num . '</td>';
echo '<td class="t ' . $taxonomy->name . 's">' . $text . '</td>';
echo '</tr><tr>';
}
// Custom post types counts
$post_types = get_post_types( array( '_builtin' => false ), 'objects' );
foreach ( $post_types as $post_type ) {
$num_posts = wp_count_posts( $post_type->name );
$num = number_format_i18n( $num_posts->publish );
$text = _n( $post_type->labels->singular_name, $post_type->labels->name, $num_posts->publish );
if ( current_user_can( 'edit_posts' ) ) {
$num = '<a href="edit.php?post_type=' . $post_type->name . '">' . $num . '</a>';
$text = '<a href="edit.php?post_type=' . $post_type->name . '">' . $text . '</a>';
}
echo '<td class="first b b-' . $post_type->name . 's">' . $num . '</td>';
echo '<td class="t ' . $post_type->name . 's">' . $text . '</td>';
echo '</tr>';
if ( $num_posts->pending > 0 ) {
$num = number_format_i18n( $num_posts->pending );
$text = _n( $post_type->labels->singular_name . ' pending', $post_type->labels->name . ' pending', $num_posts->pending );
if ( current_user_can( 'edit_posts' ) ) {
$num = '<a href="edit.php?post_status=pending&post_type=' . $post_type->name . '">' . $num . '</a>';
$text = '<a href="edit.php?post_status=pending&post_type=' . $post_type->name . '">' . $text . '</a>';
}
echo '<td class="first b b-' . $post_type->name . 's">' . $num . '</td>';
echo '<td class="t ' . $post_type->name . 's">' . $text . '</td>';
echo '</tr>';
}
}
}
?>