-
Notifications
You must be signed in to change notification settings - Fork 7
Internal Shortcode | [Post_Parent]
EkoJr edited this page Mar 17, 2017
·
2 revisions
Adds the 'Page' parent (WP_Query uses Post as a common Post/Page object).
[post_parent link="true"]
(string) (optional) Determines whether or not to add a link to the (Parent) Page Title. Default: "true"
(string) Adds Page Parent ( w/ link).
[post_parent]
Returns
<a href="LINK" >PAGE TITLE</a>
File: advanced-post-list/includes/class/apl_shortcodes.php
/**
* Page Parent Shortcode.
*
* Desc: Adds Page Parent Title, and optionally with link.
*
* 1. Check to see if Post Parent is set.
* 2. Grab Post Parent Title w/ Link if set to 'true'.
* 3. Return string.
*
* @since 0.1.0
* @version 0.4.0 - Changed to Class function, and uses WP's built-in
* functions for setting default attributes & do_shortcode().
*
* @param array $atts {
*
* Shortcode Attributes.
*
* @type string $link Returns as html link if true.
* }
* @return string Post Parent Title OR as html link.
*/
public function post_parent($atts)
{
//INIT
$atts_value = shortcode_atts( array(
'link' => 'true'
), $atts, 'post_parent');
$return_str = '';
//STEP 1
if ($this->_post->post_parent != 0)
{
//STEP 2
if (strtolower($atts_value['link']) == "false")
{
$return_str .= get_the_title($this->_post->post_parent);
}
else
{
$return_str .= '<a href="' . get_permalink($parentID) . '" >' . get_the_title($parentID) . '</a>';
}
}
//STEP 3
return $return_str;
}