Skip to content

@chrisguitarguy /seoal-dynamic.php
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Associate SEO Auto Linker links by category.
<?php
/*
Plugin Name: SEO Auto Linker Dynamic Links
Plugin URI: http
Description: Fully dynamic linking for SEO Auto Linker.
Version: 1.0
Author: Christopher Davis
Author URI: http://christopherdavis.me
License: GPL2
Copyright 2012 Christopher Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
SEOAL_Dynamic::init();
class SEOAL_Dynamic
{
// taxonomy you want to use
const TAX = 'category';
public static function init()
{
if(!class_exists('SEO_Auto_Linker_Base'))
return;
add_action(
'init',
array(__CLASS__, 'register'),
20
);
add_filter(
'seoal_links',
array(__CLASS__, 'add_links')
);
}
public static function register()
{
register_taxonomy_for_object_type(
self::TAX,
SEO_Auto_Linker_Base::POST_TYPE
);
}
public static function add_links($links)
{
global $post;
$terms = get_the_terms($post->ID, self::TAX);
if(is_wp_error($terms) || !$terms)
return array(); // no links!
/*
PHP greater than 5.3 could do this:
$new_terms = array_map(function($t) {
return $t->term_id;
}, array_values($terms));
*/
$new_terms = array();
foreach($terms as $t)
$new_terms[] = $t->term_id;
$links = get_posts(array(
'post_type' => SEO_Auto_Linker_Base::POST_TYPE,
'nopaging' => true,
'tax_query' => array(
array(
'taxonomy' => self::TAX,
'field' => 'id',
'terms' => $new_terms
)
)
));
return $links;
}
} // end SEOAL_Dyanmic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.