예제 #1
0
     *
     * @param $permalink
     * @param $id
     * @return string
     */
    public static function single_page_permalink($permalink, $id)
    {
        if ($parent_id = wp_get_post_parent_id($id)) {
            if ($parent = get_post($parent_id)) {
                if (preg_match('/single-page.php$/', get_page_template_slug($parent_id))) {
                    $post = get_post($id);
                    if (is_array($permalink)) {
                        // this is for the admin sample permalink
                        $permalink = str_replace('/%pagename%', '#%pagename%', $permalink);
                    } else {
                        if (!is_admin() && get_permalink($parent) === get_permalink()) {
                            // relative
                            $permalink = "#{$post->post_name}";
                        } else {
                            // absolute
                            $permalink = preg_replace('/\\/' . preg_quote($post->post_name, '/') . '\\/$/', "#{$post->post_name}", $permalink);
                        }
                    }
                }
            }
        }
        return $permalink;
    }
}
Filters::add();