当前位置: 首页>>代码示例>>PHP>>正文


PHP setup_postdata函数代码示例

本文整理汇总了PHP中setup_postdata函数的典型用法代码示例。如果您正苦于以下问题:PHP setup_postdata函数的具体用法?PHP setup_postdata怎么用?PHP setup_postdata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setup_postdata函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ajax_handler

 public function ajax_handler($data)
 {
     CS_Shortcode_Preserver::init();
     if ($this->sandbox_the_content) {
         CS_Shortcode_Preserver::sandbox('cs_render_the_content');
     }
     add_filter('cs_preserve_shortcodes_no_wrap', '__return_true');
     $this->orchestrator = $this->plugin->component('Element_Orchestrator');
     $this->orchestrator->load_elements();
     $this->mk1 = new Cornerstone_Legacy_Renderer($this->plugin->component('Legacy_Elements'));
     global $post;
     if (!isset($data['post_id']) || !($post = get_post((int) $data['post_id']))) {
         wp_send_json_error(array('message' => 'post_id not set'));
     }
     setup_postdata($post);
     $this->enqueue_extractor = $this->plugin->loadComponent('Enqueue_Extractor');
     $this->enqueue_extractor->start();
     if (isset($data['raw_markup'])) {
         $this->raw_markup = (bool) $data['raw_markup'];
     }
     if (!isset($data['batch'])) {
         wp_send_json_error(array('message' => 'No element data recieved'));
     }
     $jobs = $this->batch($data['batch']);
     $scripts = $this->enqueue_extractor->get_scripts();
     if (is_wp_error($jobs)) {
         wp_send_json_error(array('message' => $jobs->get_error_message()));
     }
     $result = array('jobs' => $jobs, 'scripts' => $scripts);
     //Suppress PHP error output unless debugging
     if (CS()->common()->isDebug()) {
         return wp_send_json_success($result);
     }
     return @wp_send_json_success($result);
 }
开发者ID:bitflipper1,项目名称:ghcontracting,代码行数:35,代码来源:class-builder-renderer.php

示例2: start_wp

function start_wp()
{
    global $wp_query, $post;
    // Since the old style loop is being used, advance the query iterator here.
    $wp_query->next_post();
    setup_postdata($post);
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:7,代码来源:deprecated.php

示例3: ipin_head

function ipin_head()
{
    //Opengraph
    if (is_single()) {
        global $post;
        setup_postdata($post);
        $output = '<meta property="og:type" content="article" />' . "\n";
        $output .= '<meta property="og:title" content="' . preg_replace('/[\\n\\r]/', ' ', mb_strimwidth(the_title_attribute('echo=0'), 0, 255, ' ...')) . '" />' . "\n";
        $output .= '<meta property="og:url" content="' . get_permalink() . '" />' . "\n";
        if ($post->post_content == '') {
            $meta_categories = get_the_category($post->ID);
            foreach ($meta_categories as $meta_category) {
                $meta_category_name = $meta_category->name;
            }
            if (ipin_get_post_board()) {
                $meta_board_name = ipin_get_post_board()->name;
            } else {
                $meta_board_name = __('Untitled', ipin);
            }
            $output .= '<meta property="og:description" content="' . esc_attr(__('Pinned onto', 'ipin') . ' ' . $meta_board_name . ' ' . __('Board in', 'ipin') . ' ' . $meta_category_name . ' ' . __('Category', 'ipin')) . '" />' . "\n";
        } else {
            $output .= '<meta property="og:description" content="' . esc_attr(get_the_excerpt()) . '" />' . "\n";
        }
        if (has_post_thumbnail()) {
            $imgsrc = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
            $output .= '<meta property="og:image" content="' . $imgsrc[0] . '" />' . "\n";
        }
        if (get_option('wsl_settings_Facebook_app_id')) {
            $output .= '<meta property="fb:app_id" content="' . get_option('wsl_settings_Facebook_app_id') . '" />' . "\n";
        }
        echo $output;
    }
    if (is_tax('board')) {
        global $post, $wp_query, $wp_taxonomies;
        setup_postdata($post);
        $output = '<meta property="og:type" content="article" />' . "\n";
        $output .= '<meta property="og:title" content="' . esc_attr($wp_query->queried_object->name) . '" />' . "\n";
        $output .= '<meta property="og:url" content="' . home_url('/' . $wp_taxonomies["board"]->rewrite['slug'] . '/' . sanitize_title($wp_query->queried_object->name, '_') . '/') . $wp_query->queried_object->term_id . '/" />' . "\n";
        $output .= '<meta property="og:description" content="" />' . "\n";
        if (has_post_thumbnail()) {
            $imgsrc = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
            $output .= '<meta property="og:image" content="' . $imgsrc[0] . '" />' . "\n";
        }
        echo $output;
    }
    if (is_author()) {
        global $wp_query, $wp_rewrite;
        $user_info = get_user_by('id', $wp_query->query_vars['author']);
        $output = '<meta property="og:type" content="article" />' . "\n";
        $output .= '<meta property="og:title" content="' . esc_attr($user_info->display_name) . ' (' . $user_info->user_nicename . ')" />' . "\n";
        $output .= '<meta property="og:url" content="' . home_url('/') . $wp_rewrite->author_base . '/' . $user_info->user_nicename . '/" />' . "\n";
        $output .= '<meta property="og:description" content="' . esc_attr($user_info->description) . '" />' . "\n";
        $avatar_id = get_user_meta($user_info->ID, 'ipin_user_avatar', true);
        if ($avatar_id != '' && $avatar_id != 'deleted') {
            $user_avatar = wp_get_attachment_image_src($avatar_id, 'full');
            $output .= '<meta property="og:image" content="' . $user_avatar[0] . '" />' . "\n";
        }
        echo $output;
    }
}
开发者ID:leshuis,项目名称:testwp,代码行数:60,代码来源:functions.php

示例4: wpbss_main_menu_fallback

function wpbss_main_menu_fallback()
{
    global $post;
    $args = array('post_type' => 'page', 'post_status' => 'publish', 'hierarchical' => 0);
    $pages = get_pages($args);
    //var_dump($pages);
    ?>
	<ul class="nav navbar-nav">
		<?php 
    foreach ($pages as $post) {
        setup_postdata($post);
        ?>
			<li>
				<a href="<?php 
        the_permalink();
        ?>
"><?php 
        echo $post->post_title;
        ?>
</a>
			</li>
		<?php 
    }
    wp_reset_postdata();
    ?>
	</ul>
<?php 
}
开发者ID:tanzoor,项目名称:wpbss,代码行数:28,代码来源:menu-fullwidth.php

示例5: widget

 public function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     $numberposts = isset($instance['numberposts']) ? $instance['numberposts'] : 1;
     $termargs = array('post_type' => 'glossary', 'post_status' => 'publish', 'numberposts' => $numberposts, 'orderby' => 'rand');
     if ($group = $instance['group']) {
         $termargs['tax_query'] = array(array('taxonomy' => 'wpglossarygroup', 'field' => 'slug', 'terms' => $group));
     }
     $terms = get_posts($termargs);
     if ($terms && count($terms)) {
         echo '<ul class="wpglossary widget-list">';
         foreach ($terms as $term) {
             setup_postdata($term);
             $title = '<a href="' . apply_filters('wpg_term_link', get_post_permalink($term->ID)) . '">' . get_the_title($term->ID) . '</a>';
             $desc = '';
             $display = $instance['display'];
             if ($display && $display != 'title') {
                 $desc = $display == 'full' ? apply_filters('the_content', get_the_content(), $main = false) : wpautop(get_the_excerpt());
                 $desc = '<br>' . $desc;
             }
             echo '<li>' . $title . $desc . '</li>';
         }
         wp_reset_postdata();
         echo '</ul>';
     } else {
         echo '<em>' . __('No terms available', 'wp-glossary') . '</em>';
     }
     echo $after_widget;
 }
开发者ID:s3rgiosan,项目名称:WP-Glossary,代码行数:34,代码来源:wpg-widget-random-term.class.php

示例6: widget

    /** @see WP_Widget::widget */
    function widget($args, $instance)
    {
        extract($args);
        echo $before_widget;
        $a = array("orderby" => "id", "order" => "asc");
        $categories = get_categories($a);
        foreach ($categories as $category) {
            echo $before_title;
            // var_dump($category);
            echo "<h2>" . $category->name . "</h2><ul>";
            global $post;
            $args = array('category' => $category->term_id, "numberposts" => -1, "orderby" => "title", "order" => "ASC");
            $myposts = get_posts($args);
            foreach ($myposts as $post) {
                setup_postdata($post);
                ?>
<li><a href="<?php 
                the_permalink();
                ?>
"><?php 
                the_title();
                ?>
</a></li><?php 
            }
            echo "</ul>";
            wp_reset_query();
            echo $after_title;
        }
        echo $after_widget;
    }
开发者ID:besimhu,项目名称:legacy,代码行数:31,代码来源:all-posts-by-category.php

示例7: cfct_about_text

function cfct_about_text()
{
    $about_text = get_option('cfct_about_text');
    if (!empty($about_text)) {
        $about_text = cfct_basic_content_formatting($about_text);
    } else {
        global $post, $wp_query;
        $orig_post = $post;
        isset($wp_query->query_vars['page']) ? $page = $wp_query->query_vars['page'] : ($page = null);
        // temporary - resetting below
        $wp_query->query_vars['page'] = null;
        remove_filter('the_excerpt', 'st_add_widget');
        $about_query = new WP_Query('pagename=about');
        while ($about_query->have_posts()) {
            $about_query->the_post();
            $about_text = get_the_excerpt() . sprintf(__('<a class="more" href="%s">more &rarr;</a>', 'carrington'), get_permalink());
        }
        $wp_query->query_vars['page'] = $page;
        $post = $orig_post;
        setup_postdata($post);
    }
    if (function_exists('st_add_widget')) {
        add_filter('the_excerpt', 'st_add_widget');
    }
    return $about_text;
}
开发者ID:Linuxwang,项目名称:PIE,代码行数:26,代码来源:carrington.php

示例8: get_post_by

 /**
  * Get a post by a specified field and value
  *
  * @param string $field
  * @param string $field_value
  * @param string $context Post use context (e.g. 'display')
  * @return array Post
  **/
 function get_post_by($field, $field_value, $context = 'display')
 {
     // validate input
     if (!in_array($field, array('ID', 'name'))) {
         return new WP_Error('invalid_field', 'Invalid API FIELD', 400);
     }
     if (!in_array($context, array('display', 'edit'))) {
         return new WP_Error('invalid_context', 'Invalid API CONTEXT', 400);
     }
     if ('display' === $context) {
         $args = $this->query_args();
         if (isset($args['content_width']) && $args['content_width']) {
             $GLOBALS['content_width'] = (int) $args['content_width'];
         }
     }
     if (strpos($_SERVER['HTTP_USER_AGENT'], 'wp-windows8')) {
         remove_shortcode('gallery', 'gallery_shortcode');
         add_shortcode('gallery', array(&$this, 'win8_gallery_shortcode'));
     }
     // fetch SAL post
     $post = $this->get_sal_post_by($field, $field_value, $context);
     if (is_wp_error($post)) {
         return $post;
     }
     $GLOBALS['post'] = $post;
     // TODO: not sure where this one should go
     if ('display' === $context) {
         setup_postdata($post);
     }
     $response = $this->render_response_keys($post, $context, array_keys($this->post_object_format));
     unset($GLOBALS['post']);
     return $response;
 }
开发者ID:egill,项目名称:jetpack,代码行数:41,代码来源:class.wpcom-json-api-post-v1-1-endpoint.php

示例9: postpicker_ajax_postpicker_get_post

/**
 * retrieve post
*/
function postpicker_ajax_postpicker_get_post()
{
    if (!check_ajax_referer('postpicker-ajax-nonce', 'ajaxNonce', false)) {
        die('Busted!');
    }
    $response = array('what' => 'postpicker_ajax_postpicker_get_post', 'action' => 'postpicker_ajax_postpicker_get_post', 'id' => '1');
    $results = "";
    $post_id = null;
    if (isset($_POST['post_id']) && !empty($_POST['post_id'])) {
        $post_id = $_POST['post_id'];
    }
    $asked_post = get_post($post_id);
    if ($asked_post) {
        global $post;
        $post = $asked_post;
        setup_postdata($post);
        ob_start();
        $postpick_item_template = locate_ressource(CUSTOM_PLUGIN_COMMONS_FOLDER . '/postpicker/templates/postpicker-item.php');
        if (!empty($postpick_item_template)) {
            include $postpick_item_template;
        }
        $results = ob_get_contents();
        ob_end_clean();
        wp_reset_postdata();
    }
    $response['data'] = $results;
    $xmlResponse = new WP_Ajax_Response($response);
    $xmlResponse->send();
    exit;
}
开发者ID:studio-montana,项目名称:custom,代码行数:33,代码来源:postpicker.php

示例10: patterns_meta_box

function patterns_meta_box($post)
{
    wp_nonce_field(plugin_basename(__FILE__), 'patterns_noncename');
    $html = get_post_meta($post->ID, 'html', true);
    $css = get_post_meta($post->ID, 'css', true);
    $resources = get_post_meta($post->ID, 'resources', true);
    $notes = get_post_meta($post->ID, 'notes', true);
    $height = get_post_meta($post->ID, 'height', true);
    $usepattern = get_post_meta($post->ID, 'usepattern', true);
    echo '<label for="' . $post->post_name . '"><input type="checkbox" name="usepattern" id="usepattern" value="true"' . ($usepattern ? ' checked="true"' : '') . '>Show Pattern Options</input></label><br/>';
    echo '<label class="pattern-label" for="resources">Resources</label>';
    echo '<div class="form-wrap">
  	      <fieldset>';
    $args = array('post_type' => 'resource', 'published' => true, 'meta_key' => 'priority', 'orderby' => 'meta_value_num', 'order' => 'ASC');
    $myposts = get_posts($args);
    foreach ($myposts as $post) {
        setup_postdata($post);
        echo '<label for="' . $post->post_name . '"><input type="checkbox" name="resources[]" id="' . $post->post_name . '" value="' . $post->ID . '"' . ($resources && in_array($post->ID, $resources) ? ' checked="true"' : '') . '>' . $post->post_title . '</input></label>';
    }
    wp_reset_postdata();
    echo '</fieldset>
  	      </div>';
    echo '<label class="pattern-label" for="html">Preview Height (px)</label>';
    echo '<input type="number" id="height" name="height" style="width:120px;float:left;clear:both;" value="' . ($height ? $height : "300") . '"/>';
    echo '<label class="pattern-label" for="html">HTML</label>';
    echo '<textarea id="html" name="html" rows="10" cols="90" style="width:100%">' . $html . '</textarea>';
    echo '<label class="pattern-label" for="css">CSS</label>';
    echo '<textarea id="css" name="css" rows="10" cols="90" style="width:100%">' . $css . '</textarea>';
    echo '<div class="form-wrap"><label class="pattern-label">Notes</label>	';
    wp_editor($notes, 'notes');
    echo "</div>";
}
开发者ID:alloylabs,项目名称:PatternPress,代码行数:32,代码来源:functions.php

示例11: book_shortcode

 /**
  * The shortcode to display the single book layout.
  *
  * [tb_book id="3"]
  *
  * @param $atts
  * @return string
  */
 function book_shortcode($atts)
 {
     global $post;
     extract(shortcode_atts(array('id' => false), $atts));
     if (!$id) {
         return '';
     }
     //Store The Original Post Object.
     $original_post = $post;
     $post = get_post($id);
     //Remove The Shortcode Filter to avoid a repeating loop..
     remove_filter('the_content', 'do_shortcode', 11);
     //Set The Post
     setup_postdata($post);
     ob_start();
     tb_get_template_part(apply_filters('tb_book_shortcode_template_part', 'loops/single_book'));
     echo '<div class="clear"></div>';
     $out = ob_get_contents();
     ob_end_clean();
     //Reinstate The Original Post.
     $post = $original_post;
     setup_postdata($original_post);
     //Re-Add The Filter
     add_filter('the_content', 'do_shortcode', 11);
     return $out;
 }
开发者ID:tigerstrikemedia,项目名称:totally-booked,代码行数:34,代码来源:shortcodes.php

示例12: __construct

 public function __construct($thePost = null, $mainQuery = true)
 {
     global $post;
     $this->isMainQuery = (bool) $mainQuery;
     if (is_object($thePost)) {
         $this->wpo = $thePost;
     } else {
         if (is_numeric($thePost)) {
             $this->wpo = get_post($thePost);
         } else {
             if (is_string($thePost)) {
                 $this->wpo = new \WP_Query(array('name' => $thePost));
             } else {
                 $this->wpo = $post;
             }
         }
     }
     /*
     		@link https://codex.wordpress.org/Function_Reference/setup_postdata
     		Sets up global post data. Helps to format custom query results for using Template tags.
     		setup_postdata() fills the global variables $id, $authordata, $currentday, $currentmonth,
     		$page, $pages, $multipage, $more, $numpages, which help many Template Tags work in the
     		current post context. It does not assign the global $post variable, but seems to expect
     		that its argument is a reference to it.
     */
     if ($this->isMainQuery) {
         setup_postdata($this->wpo);
     }
 }
开发者ID:bruno-barros,项目名称:w.eloquent-framework,代码行数:29,代码来源:BasePresenter.php

示例13: process

 public static function process()
 {
     theme_features::check_referer();
     $post_id = isset($_GET['post-id']) && is_numeric($_GET['post-id']) ? (int) $_GET['post-id'] : false;
     if (!$post_id) {
         die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_post_id', 'msg' => ___('Sorry, post id is invaild.')]));
     }
     global $post, $page;
     /**
      * post
      */
     $post = theme_cache::get_post($post_id);
     if (!$post) {
         die(theme_features::json_format(['status' => 'error', 'code' => 'post_not_exist', 'msg' => ___('Sorry, the post does not exist.')]));
     }
     /**
      * page
      */
     $page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : false;
     if (!$page) {
         die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_page_number', 'msg' => ___('Sorry, page number is invaild.')]));
     }
     set_query_var('page', $page);
     setup_postdata($post);
     ob_start();
     if (class_exists('theme_img_lazyload')) {
         remove_filter('the_content', 'theme_img_lazyload::the_content');
     }
     the_content();
     $content = html_minify(ob_get_contents());
     ob_end_clean();
     die(theme_features::json_format(['status' => 'success', 'content' => $content]));
 }
开发者ID:ClayMoreBoy,项目名称:mx,代码行数:33,代码来源:page-nagination-ajax.php

示例14: mpp_filter_latest_comic

/**
 * Handles display for the latest comic page.
 *
 * @global object $mp MangaPress bootstrap object
 * @global object $post WordPress Post
 * @global array $_wp_additional_image_sizes Array defining thumbnail names and dimensions.
 *
 * @since 2.7
 * @param string $template
 * @return string
 */
function mpp_filter_latest_comic($content)
{
    global $post, $mp, $_wp_additional_image_sizes;
    $mp_options = $mp->get_options();
    if (!($post->post_name == $mp_options['basic']['latestcomic_page'])) {
        return $content;
    } else {
        global $thumbnail_size, $single_comic_query;
        $single_comic_query = mpp_get_latest_comic();
        if ($single_comic_query instanceof WP_Error) {
            return apply_filters('the_latest_comic_content_error', '<p class="error">No Latest Comic was found.</p>');
        }
        $thumbnail_size = 'comic-page';
        if (!isset($_wp_additional_image_sizes['comic-page'])) {
            $thumbnail_size = 'large';
        }
        if (!isset($single_comic_query->posts[0])) {
            ob_start();
            load_template(MP_ABSPATH . 'templates/content/no-comics.php', true);
            $content = ob_get_contents();
            ob_end_clean();
        } else {
            $post = $single_comic_query->posts[0];
            setup_postdata($post);
            ob_start();
            load_template(MP_ABSPATH . 'templates/content/latest-comic.php', true);
            $content = ob_get_contents();
            ob_end_clean();
        }
        return apply_filters('the_latest_comic_content', $content);
    }
}
开发者ID:TheProjecter,项目名称:mangapress,代码行数:43,代码来源:functions.php

示例15: estimate_embed

 public static function estimate_embed($atts = array())
 {
     do_action('sprout_invoices_estimate_embed');
     $estimate_id = 0;
     // Make sure id given is for an invoice
     if (isset($atts['id'])) {
         $estimate_id = (int) $atts['id'];
     }
     if (isset($_GET['si_id'])) {
         $estimate_id = (int) $_GET['si_id'];
     }
     if (SI_Estimate::POST_TYPE !== get_post_type($estimate_id)) {
         return;
     }
     // enqueue style
     self::frontend_enqueue();
     // Show snippet view or not.
     $embed_view = '';
     if (isset($atts['snippet']) && 'true' === $atts['snippet']) {
         $embed_view = '-snippet';
     }
     self::remove_actions();
     // Setup global post for filters and functions to work
     global $post;
     $post = get_post($estimate_id);
     setup_postdata($post);
     $estimate = SI_Estimate::get_instance($estimate_id);
     $line_items = $estimate->get_line_items();
     $view = self::load_addon_view_to_string('estimates/embed' . $embed_view, array('id' => $estimate_id, 'line_items' => $line_items, 'prev_type' => '', 'totals' => SI_Line_Items::line_item_totals($estimate_id)), false);
     // reset to the original post
     wp_reset_postdata();
     return $view;
 }
开发者ID:danielbachhuber,项目名称:marcgratch.com,代码行数:33,代码来源:Embeds.php


注:本文中的setup_postdata函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。