Skip to content

Commit

Permalink
Merge pull request #1094 from INN/1090-fix
Browse files Browse the repository at this point in the history
1090 fix
  • Loading branch information
benlk committed Jan 25, 2016
2 parents 5eb72f5 + 910ac8d commit 4e46fde
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion inc/post-metaboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function largo_top_tag_display() {
foreach ($terms as $term)
echo '<option value="' . (int) $term->term_id . '"' . selected( $term->term_id, $top_term, FALSE ) . ">" . $term->name . '</option>';

echo '<option value="null"' . selected( 'null' , $top_term, FALSE ) . ">None</option>";
echo '<option value="none"' . selected( 'none' , $top_term, FALSE ) . ">None</option>";
echo '</select>';
}
largo_add_meta_content('largo_top_tag_display', 'largo_additional_options');
Expand Down
39 changes: 32 additions & 7 deletions inc/related-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,39 @@ function largo_top_term( $options = array() ) {

$args = wp_parse_args( $options, $defaults );

/*
* Try to get a term ID
* Or continue using 'none' if that is the case
*/
$term_id = get_post_meta( $args['post'], 'top_term', TRUE );

if ( ! $term_id == 'null' ) { // if term id is 'null' for the "None" option, don't bother doing this.
// Try to get the taxonomy for the term ID, but if it's 'none' for the "None" option, don't bother doing this.
if ( !empty($term_id) && $term_id !== 'none' ) {
//get the taxonomy slug
$taxonomy = $wpdb->get_var( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $term_id) );
}

if ( empty( $term_id ) || ( empty($taxonomy) && $term_id != 'null' ) ) { // if no top_term specified, fall back to the first category
// if no top_term specified, or if the top term is not in a taxonomy and the top term is not 'none',
if ( empty( $term_id ) || ( empty($taxonomy) && $term_id !== 'none' ) ) {
// Get the categories the post is in and try to use the first one as a term id
$term_id = get_the_category( $args['post'] );
if ( !is_array( $term_id ) || !count($term_id) ) return; //no categories OR top term? Do nothing
$term_id = $term_id[0]->term_id;
if ( is_array( $term_id ) && count($term_id) ) {
$term_id = $term_id[0]->term_id;
}

// The post isn't in a category? Try post-types if that's enabled.
if ( empty($term_id) && taxonomy_exists('post-type') ) {
$term_id = get_the_terms( $args['post'], 'post-type' );
if ( is_array( $term_id ) && count($term_id) ) {
$term_id = $term_id[0]->term_id;
}
}
}

if ( $term_id && $term_id != 'null' ) {
/*
* Using the term ID, get the term and then generate some text
*/
if ( $term_id && $term_id !== 'none' && !empty($taxonomy) ) {
$icon = ( $args['use_icon'] ) ? '<i class="icon-white icon-tag"></i>' : '' ; //this will probably change to a callback largo_term_icon() someday
$link = ( $args['link'] ) ? array('<a href="%2$s" title="Read %3$s in the %4$s category">','</a>') : array('', '') ;
// get the term object
Expand All @@ -343,7 +362,13 @@ function largo_top_term( $options = array() ) {
$term->name,
$icon
);
} else {
}

/*
* No output?
* generate a link to the post's category or tags
*/
if ( empty($output) ) {
$output = largo_categories_and_tags( 1, false, $args['link'], $args['use_icon'], '', $args['wrapper'], $args['exclude']);
$output = ( is_array($output) ) ? $output[0] : '';
}
Expand All @@ -352,7 +377,7 @@ function largo_top_term( $options = array() ) {
* for https://github.com/INN/Largo/issues/1082, support not outputting anything
* @since 0.5.5
*/
if ( $term_id == 'null' ) {
if ( $term_id == 'none' ) {
$output = '';
}

Expand Down

0 comments on commit 4e46fde

Please sign in to comment.