Custom link back to posts category
-
I was needing a link saying “back” that pointed to the category that the post was originally posted in. So I wrote this short plugin, I thought someone might use it.
<?php
/*
Plugin Name: Parent Category
Plugin URI:
Description: Adds a link to the parent category in the single.php template. To use, call the_parent_category_link(); where you want the link to appear.
Author: Niels Hackius
Version: 0.1
Author URI: https://hackius.de/niels
*/
/*
*Notes
*------
*based upon Parent Link (https://www.ads-software.com/support/topic/33894)
*by Denis de Bernardy(https://www.semiologic.com)
**/
/*
* Terms of use
* ------------
* Except where otherwise noted, this software is:
* - Copyright 2005, Niels Hackius
* - Licensed under the terms of the CC/GNU GPL
* https://creativecommons.org/licenses/GPL/2.0/
* - Provided as is, with NO WARRANTY whatsoever
**/
/*
*Usage
*-----
*@param string $text optional specifies the string being displayed if used for direct output, defaults to "back"
*@param boolean $selector optional if false the function only returns the url for use with php, if true it echos the string
*
*to use just write:
*<?php echo the the_parent_category_link() ?>
**/
function the_parent_category_link($text = "back", $selector = true)
{
global $post;
if ( !isset($post->post_category) ) {
return;
}
$url = get_settings('siteurl').'/index.php?cat='.$post->post_category;
if(!$selector) {
return $url;
}
else {
echo '<a href="'.$url.'">'.$text.'</a>';
}
}?>
- The topic ‘Custom link back to posts category’ is closed to new replies.