Yoast Breadcrumbs - Version 0.6.1

Version Description

Download this release

Release Info

Developer joostdevalk
Plugin Icon wp plugin Yoast Breadcrumbs
Version 0.6.1
Comparing to
See all releases

Version 0.6.1

Files changed (3) hide show
  1. readme.txt +32 -0
  2. yoast-breadcrumbs.php +233 -0
  3. yoast-posts.php +60 -0
readme.txt ADDED
@@ -0,0 +1,32 @@
1
+ === Yoast Breadcrumbs ===
2
+ Contributors: joostdevalk
3
+ Donate link: http://yoast.com/donate/
4
+ Tags: rss, footer
5
+ Requires at least: 2.2
6
+ Tested up to: 2.6
7
+ stable tag: 0.6.1
8
+
9
+ Easily add breadcrumbs to your template!
10
+
11
+ == Description ==
12
+
13
+ Easily add breadcrumbs to your template.
14
+
15
+ More info:
16
+
17
+ * [Yoast Breadcrumbs](http://yoast.com/wordpress/breadcrumbs/).
18
+ * Read more about how to improve your [WordPress SEO](http://yoast.com/articles/wordpress-seo/), so you can get the most out of this plugin.
19
+ * Check out the other [Wordpress plugins](http://yoast.com/wordpress/) by the same author.
20
+
21
+ == Installation ==
22
+
23
+ Installation is easy:
24
+
25
+ * Download the plugin
26
+ * Unzip the package and upload the file to your WordPress installation's plugins folder
27
+ * Enable the plugin
28
+ * Adjust any settings you want under Settings -> Breadcrumbs
29
+ * Add the following code to your theme's template(s):
30
+ `<?php if ( function_exists('yoast_breadcrumb') {
31
+ yoast_breadcrumb('<p id="breadcrumbs">','</p>');
32
+ } )?>`
yoast-breadcrumbs.php ADDED
@@ -0,0 +1,233 @@
1
+ <?php /*
2
+ Plugin Name: Yoast Breadcrumbs
3
+ Plugin URI: http://yoast.com/wordpress/breadcrumbs/
4
+ Description: Outputs a fully customizable breadcrumb path.
5
+ Version: 0.6.1
6
+ Author: Joost de Valk
7
+ Author URI: http://yoast.com/
8
+
9
+ Copyright (C) 2008, Joost de Valk
10
+ All rights reserved.
11
+
12
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
13
+
14
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
15
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
16
+ Neither the name of Joost de Valk or Yoast nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
18
+
19
+ // Load some defaults
20
+ $opt = array();
21
+ $opt['home'] = "Home";
22
+ $opt['sep'] = "&raquo;";
23
+ $opt['prefix'] = "You are here:";
24
+ $opt['boldlast'] = true;
25
+ $opt['nofollowhome'] = false;
26
+ $opt['singleparent'] = 0;
27
+ $opt['singlecatprefix'] = true;
28
+ $opt['archiveprefix'] = "Archives for";
29
+ $opt['searchprefix'] = "Search for";
30
+ add_option("yoast_breadcrumbs",$opt);
31
+
32
+ if ( ! class_exists( 'YoastBreadcrumbs_Admin' ) ) {
33
+
34
+ class YoastBreadcrumbs_Admin {
35
+
36
+ function add_config_page() {
37
+ global $wpdb;
38
+ if ( function_exists('add_submenu_page') ) {
39
+ add_options_page('Yoast Breadcrumbs Configuration', 'Breadcrumbs', 10, basename(__FILE__),array('YoastBreadcrumbs_Admin','config_page'));
40
+ }
41
+ }
42
+
43
+ function config_page() {
44
+ if ( isset($_POST['submit']) ) {
45
+ if (!current_user_can('manage_options')) die(__('You cannot edit the Yoast Breadcrumbs options.'));
46
+ check_admin_referer('yoast-breadcrumbs-updatesettings');
47
+
48
+ foreach (array('home', 'sep', 'singleparent', 'prefix', 'archiveprefix', 'searchprefix', 'breadcrumbprefix', 'breadcrumbsuffix') as $option_name) {
49
+ if (isset($_POST[$option_name])) {
50
+ $opt[$option_name] = htmlentities(html_entity_decode($_POST[$option_name]));
51
+ }
52
+ }
53
+
54
+ foreach (array('boldlast', 'nofollowhome', 'singlecatprefix') as $option_name) {
55
+ if (isset($_POST[$option_name])) {
56
+ $opt[$option_name] = true;
57
+ } else {
58
+ $opt[$option_name] = false;
59
+ }
60
+ }
61
+
62
+ update_option('yoast_breadcrumbs', $opt);
63
+ }
64
+
65
+ $opt = get_option('yoast_breadcrumbs');
66
+ ?>
67
+ <div class="wrap">
68
+ <h2>Yoast Breadcrumbs Configuration</h2>
69
+ <form action="" method="post" id="yoastbreadcrumbs-conf">
70
+ <table class="form-table">
71
+ <?php if (function_exists('wp_nonce_field')) { wp_nonce_field('yoast-breadcrumbs-updatesettings'); } ?>
72
+ <tr>
73
+ <th scope="row" valign="top"><label for="sep">Separator between breadcrumbs:</label></th>
74
+ <td><input type="text" name="sep" id="sep" value="<?php echo htmlentities($opt['sep']); ?>"/></td>
75
+ </tr>
76
+ <tr>
77
+ <th scope="row" valign="top"><label for="home">Anchor text for the Homepage:</label></th>
78
+ <td><input type="text" name="home" id="home" value="<?php echo $opt['home']; ?>"/></td>
79
+ </tr>
80
+ <tr>
81
+ <th scope="row" valign="top"><label for="prefix">Prefix for the breadcrumb path:</label></th>
82
+ <td><input type="text" name="prefix" id="prefix" value="<?php echo $opt['prefix']; ?>"/></td>
83
+ </tr>
84
+ <tr>
85
+ <th scope="row" valign="top"><label for="archiveprefix">Prefix for Archive breadcrumbs:</label></th>
86
+ <td><input type="text" name="archiveprefix" id="archiveprefix" value="<?php echo $opt['archiveprefix']; ?>"/></td>
87
+ </tr>
88
+ <tr>
89
+ <th scope="row" valign="top"><label for="searchprefix">Prefix for Search Page breadcrumbs:</label></th>
90
+ <td><input type="text" name="searchprefix" id="searchprefix" value="<?php echo $opt['searchprefix']; ?>"/></td>
91
+ </tr>
92
+ <tr>
93
+ <th scope="row" valign="top"><label for="singlecatprefix">Show category in post breadcrumbs? <small style="font-weight: normal;">(Shows the category inbetween Home and the blogpost)</small></label></th>
94
+ <td><input type="checkbox" id="singlecatprefix" name="singlecatprefix" <?php if ($opt['singlecatprefix']) { echo 'checked="checked"'; } ?>/></td>
95
+ </tr>
96
+ <tr>
97
+ <th scope="row" valign="top"><label for="singleparent">Show Parent Page for Blog posts?</label> <small style="font-weight: normal;">(Adds another page inbetween Home and the blogpost)</small></th>
98
+ <td><?php wp_dropdown_pages("depth=0&name=singleparent&show_option_none=-- None --&selected=".$opt['singleparent']); ?></td>
99
+ </tr>
100
+ <tr>
101
+ <th scope="row" valign="top"><label for="boldlast">Bold the last page in the breadcrumb?</label></th>
102
+ <td><input type="checkbox" id="boldlast" name="boldlast" <?php if ($opt['boldlast']) { echo 'checked="checked"'; } ?>/></td>
103
+ </tr>
104
+ <tr>
105
+ <th scope="row" valign="top"><label for="nofollowhome">Nofollow the link to the home page?</label></th>
106
+ <td><input type="checkbox" id="nofollowhome" name="nofollowhome" <?php if ($opt['nofollowhome']) { echo 'checked="checked"'; } ?>/></td>
107
+ </tr>
108
+ </table>
109
+ <br/>
110
+ <span class="submit" style="border: 0;"><input type="submit" name="submit" value="Save Settings" /></span>
111
+ </form>
112
+ </div>
113
+ <?php }
114
+ }
115
+ }
116
+
117
+ function yoast_breadcrumb($prefix = '', $suffix = '', $display = true) {
118
+ global $wp_query, $post;
119
+
120
+ $opt = get_option("yoast_breadcrumbs");
121
+
122
+ function bold_or_not($input) {
123
+ $opt = get_option("yoast_breadcrumbs");
124
+ if ($opt['boldlast']) {
125
+ return '<strong>'.$input.'</strong>';
126
+ } else {
127
+ return $input;
128
+ }
129
+ }
130
+
131
+ // Copied and adapted from WP source
132
+ function yoast_get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE){
133
+ $chain = '';
134
+ $parent = &get_category($id);
135
+ if ( is_wp_error( $parent ) )
136
+ return $parent;
137
+
138
+ if ( $nicename )
139
+ $name = $parent->slug;
140
+ else
141
+ $name = $parent->cat_name;
142
+
143
+ if ( $parent->parent && ($parent->parent != $parent->term_id) )
144
+ $chain .= get_category_parents($parent->parent, true, $separator, $nicename);
145
+
146
+ $chain .= bold_or_not($name);
147
+ return $chain;
148
+ }
149
+
150
+ $nofollow = ' ';
151
+ if ($opt['nofollowhome']) {
152
+ $nofollow = ' rel="nofollow" ';
153
+ }
154
+
155
+ $homelink = '<a'.$nofollow.'href="'.get_bloginfo('wpurl').'">'.$opt['home'].'</a>';
156
+
157
+ if ( is_home() || is_front_page() ) {
158
+ $output = bold_or_not($opt['home']);
159
+ } elseif ( !is_page() ) {
160
+ $output = $homelink.' '.$opt['sep'].' ';
161
+ if ( ( is_single() || is_category() || is_tag() || is_date() || is_author() ) && $opt['singleparent'] != 0) {
162
+ $output .= '<a href="'.get_permalink($opt['singleparent']).'">'.get_the_title($opt['singleparent']).'</a> '.$opt['sep'].' ';
163
+ }
164
+ if (is_single() && $opt['singlecatprefix']) {
165
+ $cats = get_the_category();
166
+ $cat = $cats[0];
167
+ $output .= get_category_parents($cat->term_id, true, " ".$opt['sep']." ");
168
+ }
169
+ if ( is_category() ) {
170
+ $cat = intval( get_query_var('cat') );
171
+ $output .= yoast_get_category_parents($cat, false, " ".$opt['sep']." ");
172
+ } elseif ( is_tag() ) {
173
+ $output .= bold_or_not($opt['archiveprefix']." ".single_cat_title('',false));
174
+ } elseif (is_date()) {
175
+ $output .= bold_or_not($opt['archiveprefix']." ".single_month_title(' ',false));
176
+ } elseif (is_author()) {
177
+ $user = get_userdatabylogin($wp_query->query_vars['author_name']);
178
+ $output .= bold_or_not($opt['archiveprefix']." ".$user->display_name);
179
+ } elseif (is_search()) {
180
+ $output .= bold_or_not($opt['searchprefix'].' "'.get_search_query().'"');
181
+ } else {
182
+ $output .= bold_or_not(get_the_title());
183
+ }
184
+ } else {
185
+ $post = $wp_query->get_queried_object();
186
+
187
+ // If this is a top level Page, it's simple to output the breadcrumb
188
+ if ( 0 == $post->post_parent ) {
189
+ $output = $homelink." ".$opt['sep']." ".bold_or_not(get_the_title());
190
+ } else {
191
+ $ancestors = array_values($post->ancestors);
192
+ // Reverse the order so it's oldest to newest
193
+ $ancestors = array_reverse($ancestors);
194
+
195
+ // Add the current Page to the ancestors list (as we need it's title too)
196
+ $ancestors[] = $post->ID;
197
+
198
+ $links = array();
199
+ foreach ( $ancestors as $ancestor ) {
200
+ $tmp = array();
201
+ $tmp['title'] = strip_tags( get_the_title( $ancestor ) );
202
+ $tmp['url'] = get_permalink($ancestor);
203
+ if ($ancestor == $post->ID) {
204
+ $tmp['cur'] = true;
205
+ }
206
+ $links[] = $tmp;
207
+ }
208
+
209
+ $output = $homelink;
210
+ foreach ( $links as $link ) {
211
+ $output .= ' '.$opt['sep'].' ';
212
+ if (!$link['cur']) {
213
+ $output .= '<a href="'.$link['url'].'">'.$link['title'].'</a>';
214
+ } else {
215
+ $output .= bold_or_not($link['title']);
216
+ }
217
+ }
218
+ }
219
+ }
220
+ if ($opt['prefix'] != "") {
221
+ $output = $opt['prefix']." ".$output;
222
+ }
223
+ if ($display) {
224
+ echo $prefix.$output.$suffix;
225
+ } else {
226
+ return $prefix.$output.$suffix;
227
+ }
228
+ }
229
+
230
+ add_action('admin_menu', array('YoastBreadcrumbs_Admin','add_config_page'));
231
+
232
+ require("yoast-posts.php");
233
+ ?>
yoast-posts.php ADDED
@@ -0,0 +1,60 @@
1
+ <?php
2
+
3
+ if (!class_exists('YoastPosts')) {
4
+ class YoastPosts {
5
+
6
+ // Class initialization
7
+ function YoastPosts() {
8
+ if (isset($_GET['show_yoast_widget'])) {
9
+ if ($_GET['show_yoast_widget'] == "true") {
10
+ update_option( 'show_yoast_widget', 'noshow' );
11
+ } else {
12
+ update_option( 'show_yoast_widget', 'show' );
13
+ }
14
+ }
15
+
16
+ // Add the widget to the dashboard
17
+ add_action( 'wp_dashboard_setup', array(&$this, 'register_widget') );
18
+ add_filter( 'wp_dashboard_widgets', array(&$this, 'add_widget') );
19
+ }
20
+
21
+ // Register this widget -- we use a hook/function to make the widget a dashboard-only widget
22
+ function register_widget() {
23
+ wp_register_sidebar_widget( 'yoast_posts', __( 'Yoast - Tweaking Websites', 'yoast-posts' ), array(&$this, 'widget'), array( 'all_link' => 'http://yoast.com/', 'feed_link' => 'http://yoast.com/feed/', 'edit_link' => 'options.php' ) );
24
+ }
25
+
26
+ // Modifies the array of dashboard widgets and adds this plugin's
27
+ function add_widget( $widgets ) {
28
+ global $wp_registered_widgets;
29
+ if ( !isset($wp_registered_widgets['yoast_posts']) ) return $widgets;
30
+ array_splice( $widgets, 2, 0, 'yoast_posts' );
31
+ return $widgets;
32
+ }
33
+
34
+ function widget($args) {
35
+ $show = get_option('show_yoast_widget');
36
+ if ($show != 'noshow') {
37
+ extract( $args, EXTR_SKIP );
38
+ echo $before_widget.$before_title.$widget_name.$after_title;
39
+ echo '<a href="http://yoast.com/"><img style="margin: 0 0 5px 5px;" src="http://yoast.com/images/yoast-logo-rss.png" align="right" alt="Yoast"/></a>';
40
+ include_once(ABSPATH . WPINC . '/rss.php');
41
+ $rss = fetch_rss('http://feeds.feedburner.com/joostdevalk');
42
+ $items = array_slice($rss->items, 0, 2);
43
+ ?>
44
+ <?php if (empty($items)) echo '<li>No items</li>';
45
+ else
46
+ foreach ( $items as $item ) : ?>
47
+ <a style="font-size: 14px; font-weight:bold;" href='<?php echo $item['link']; ?>' title='<?php echo $item['title']; ?>'><?php echo $item['title']; ?></a> <span style="font-size: 14px; color: #aaa;"><?php echo date('j F Y',strtotime($item['pubdate'])); ?></span><br/>
48
+ <?php echo substr($item['summary'],0,strpos($item['summary'], "This is a post from")); ?>
49
+ <br/>
50
+ <?php endforeach;
51
+ echo '<p style="float:right;"><a href="?show_yoast_widget=true">Remove this widget</a></p>';
52
+ echo $after_widget;
53
+ }
54
+ }
55
+ }
56
+
57
+ // Start this plugin once all other plugins are fully loaded
58
+ add_action( 'plugins_loaded', create_function( '', 'global $YoastPosts; $YoastPosts = new YoastPosts();' ) );
59
+ }
60
+ ?>