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


PHP Posts::update方法代码示例

本文整理汇总了PHP中Posts::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::update方法的具体用法?PHP Posts::update怎么用?PHP Posts::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Posts的用法示例。


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

示例1: edit

 public function edit($id)
 {
     // find article
     if (($article = Posts::find(array('id' => $id))) === false) {
         return Response::redirect($this->admin_url . '/posts');
     }
     // process post request
     if (Input::method() == 'POST') {
         if (Posts::update($id)) {
             // redirect path
             return Response::redirect($this->admin_url . '/posts/edit/' . $id);
         }
     }
     // get comments
     $comments = Comments::list_all(array('post' => $id));
     $pending = array();
     foreach ($comments as $comment) {
         if ($comment->status == 'pending') {
             $pending[] = $comment->id;
         }
     }
     $pending = count($pending);
     // get posts page
     $page = Pages::find(array('id' => Config::get('metadata.posts_page')));
     Template::render('posts/edit', array('article' => $article, 'comments' => $comments, 'page' => $page, 'pending' => $pending));
 }
开发者ID:nathggns,项目名称:anchor-cms,代码行数:26,代码来源:posts.php

示例2: get

 /**
  * @param int    $post_id
  * @param string $post_type
  * @param string $key
  *
  * @return \WP_Post
  */
 public static function get($post_id = 0, $post_type = 'post', $key = '')
 {
     $args = ['ignore_sticky_posts' => true];
     if (defined('DOING_AJAX') && DOING_AJAX) {
         $args['post_type'] = array_keys(static::$_post_types);
         if ($post_id) {
             $args['p'] = $post_id;
             $post = current((new \WP_Query($args))->get_posts());
         } else {
             Posts::update($key, $post_id);
             $post = null;
         }
     } else {
         if (is_null(static::$_posts)) {
             $args['post_type'] = array_keys(static::$_post_types);
             $args['posts_per_page'] = -1;
             $ids = array_values(static::get_ids());
             if (!empty($ids)) {
                 $args['post__in'] = $ids;
                 $the_query = new \WP_Query($args);
                 while ($the_query->have_posts()) {
                     $the_query->the_post();
                     $_post_type = get_post_type();
                     if (!isset(static::$_posts[$_post_type])) {
                         static::$_posts[$_post_type] = [];
                     }
                     static::$_posts[$_post_type][get_the_ID()] = get_post();
                 }
                 wp_reset_postdata();
                 $args['post__not_in'] = $ids;
                 unset($args['post__in']);
             }
             foreach (static::$_post_types as $_post_type => $_posts_per_page) {
                 if (!isset(static::$_posts[$_post_type])) {
                     static::$_posts[$_post_type] = [];
                 }
                 $_found_posts = count(static::$_posts[$_post_type]);
                 if ($_found_posts < $_posts_per_page) {
                     $args['post_type'] = $_post_type;
                     $args['posts_per_page'] = $_posts_per_page - $_found_posts;
                     $the_query = new \WP_Query($args);
                     static::$_query_args[$_post_type] = ['offset' => $the_query->post_count];
                     static::$_posts[$_post_type]['recent'] = $the_query->get_posts();
                 }
             }
         }
         if ($post_id && isset(static::$_posts[$post_type][$post_id])) {
             $post = static::$_posts[$post_type][$post_id];
             unset(static::$_posts[$post_type][$post_id]);
         } else {
             $post_id = key(static::$_posts[$post_type]['recent']);
             $post = isset(static::$_posts[$post_type]['recent'][$post_id]) ? static::$_posts[$post_type]['recent'][$post_id] : null;
             unset(static::$_posts[$post_type]['recent'][$post_id]);
         }
     }
     return $post;
 }
开发者ID:Viktor777,项目名称:wp-customize-builder,代码行数:64,代码来源:Posts.php

示例3: date

         if (!isset($_POST['title']) || $_POST['title'] == "") {
             $alertred[] = TITLE_CANNOT_EMPTY;
         }
         if (isset($alertred)) {
             $data['alertred'] = $alertred;
         } else {
             if (!isset($_POST['date']) || $_POST['date'] == "") {
                 # code...
                 $date = date("Y-m-d H:i:s");
             } else {
                 $date = $_POST['date'];
             }
             $moddate = date("Y-m-d H:i:s");
             $vars = array('title' => $title, 'content' => $content, 'modified' => $moddate, 'date' => $date, 'status' => Typo::int($_POST['status']));
             //print_r($vars);
             Posts::update($vars);
             $data['alertgreen'][] = PAGE . "  {$_POST['title']} " . MSG_PAGE_UPDATED;
             Token::remove($_POST['token']);
         }
         break;
     default:
         # code...
         //System::inc('posts_form', $data);
         break;
 }
 $id = Typo::int($_GET['id']);
 $data['post'] = Db::result("SELECT * FROM `posts` AS A \n            LEFT JOIN `posts_param` AS B\n            ON A.`id` = B.`post_id` \n            WHERE A.`id` = '{$id}' ");
 Theme::admin('header', $data);
 System::inc('pages_form', $data);
 Theme::admin('footer');
 break;
开发者ID:vdanelia,项目名称:GeniXCMS,代码行数:31,代码来源:pages.control.php


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