/** * Set up global post data. * * @since 1.5.0 * * @param object $post Post data. * @uses do_action_ref_array() Calls 'the_post' * @return bool True when finished. */ function setup_postdata($post) { global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages; $id = (int) $post->ID; $authordata = get_userdata($post->post_author); $currentday = mysql2date('d.m.y', $post->post_date, false); $currentmonth = mysql2date('m', $post->post_date, false); $numpages = 1; $page = get_query_var('page'); if (!$page) { $page = 1; } if (is_single() || is_page() || is_feed()) { $more = 1; } extract(wp_parse_post_content($post, false)); if ($multipage && $page > 1) { $more = 1; } do_action_ref_array('the_post', array(&$post)); return true; }
/** * Retrieve the post content. * * @since 0.71 * * @param string $more_link_text Optional. Content for when there is more text. * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false. * @param int $id Optional. A post id. Defaults to the current post when in The Loop, undefined otherwise. * @return string */ function get_the_content($more_link_text = null, $strip_teaser = false, $id = 0) { global $page, $more, $preview; $post = get_post($id); // Avoid parsing again if the post is the same one parsed by setup_postdata(). // The extract() will set up $pages and $multipage. if ($post->ID != $GLOBALS['id']) { extract(wp_parse_post_content($post, false)); } else { global $pages, $multipage; } if (null === $more_link_text) { $more_link_text = __('(more…)'); } $output = ''; $has_teaser = false; // If post password required and it doesn't match the cookie. if (post_password_required($post)) { return get_the_password_form($post); } if ($page > count($pages)) { // if the requested page doesn't exist $page = count($pages); } // give them the highest numbered page that DOES exist $content = $pages[$page - 1]; if (preg_match('/<!--more(.*?)?-->/', $content, $matches)) { $content = explode($matches[0], $content, 2); if (!empty($matches[1]) && !empty($more_link_text)) { $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1]))); } $has_teaser = true; } else { $content = array($content); } if (false !== strpos($post->post_content, '<!--noteaser-->') && (!$multipage || $page == 1)) { $strip_teaser = true; } $teaser = $content[0]; if ($more && $strip_teaser && $has_teaser) { $teaser = ''; } $output .= $teaser; if (count($content) > 1) { if ($more) { $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; } else { if (!empty($more_link_text)) { $output .= apply_filters('the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">{$more_link_text}</a>", $more_link_text); } $output = force_balance_tags($output); } } if ($preview) { // preview fix for javascript bug with foreign languages $output = preg_replace_callback('/\\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output); } return $output; }