Created
February 25, 2012 22:11
-
-
Save nerrad/1911141 to your computer and use it in GitHub Desktop.
Organize Series and organize-series-multiples: allowing for post links for posts that belong to multiple series to have a context saved when clicked from series archive page. This doesn't work as is - gonna move to the main file and fix.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('init', 'modify_series_link_context'); | |
function modify_series_link_context() { | |
add_filter('post_link', 'multi_series_link_mod', 10, 3); | |
add_filter('get_the_series', 'multi_series_get_mod'); | |
} | |
function multi_series_link_mod($permalink, $post, $leavename) { | |
//is the displayed page a series archive page? If so, then let's make sure we append a request variable to the post links for this series. | |
$new_link = $permalink; | |
if ( is_series() ) { | |
$series_id = get_query_var(SERIES_QUERYVAR); | |
if ( !is_numeric($series_slug) ) { | |
$series_id = get_term_by('name', htmlentities2($series_id), 'series'); | |
} | |
if ( empty($series_id) ) | |
return false; //get out we need a series id | |
$new_link = add_query_arg('ref_ser', $series_id, $permalink); | |
} | |
//k now let's see if we've been referred by a series archive page | |
if ( $ref_ser = get_query_var('ref_ser') ) { | |
$series_id = $ref_ser; | |
$new_link = add_query_arg('ref_ser', $series_id, $permalink); | |
} | |
return $new_link; | |
} | |
function multi_series_get_mod($series) { | |
//let's filter drop any series that don't match the series_id (if present) in the $_REQUEST array | |
if ( $ref = get_query_var('ref_ser') ) { | |
$series_id = $ref_ser; | |
if ( $series->term_id != $ref_ser ) | |
return false; | |
} | |
return $series; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment