當前位置: 首頁>>代碼示例>>PHP>>正文


PHP url_to_postid函數代碼示例

本文整理匯總了PHP中url_to_postid函數的典型用法代碼示例。如果您正苦於以下問題:PHP url_to_postid函數的具體用法?PHP url_to_postid怎麽用?PHP url_to_postid使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了url_to_postid函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: cap_redirect_short_urls

/**
 * This function handles the actual redirection to the target.
 */
function cap_redirect_short_urls()
{
    global $post;
    if (is_singular('cap_short_urls')) {
        // Check for the existance of legacy url information. Lead with that if present.
        if (get_post_meta($post->ID, 'legacy_url_redirect_target', true)) {
            $legacy_url = get_post_meta($post->ID, 'legacy_url_redirect_target', true);
            // Let's get the actual domain from the legacy url...
            $parse = parse_url($legacy_url);
            $domain = $parse['host'];
            // ... if it is thinkprogress.org then proceed with idenfication of the post targeted. Otherwise just do a straight up redirect.
            if ('thinkprogress.org' === $domain || 'www.thinkprogress.org' === $domain) {
                // We could probably just get away with passing the old url in however... we want to make sure that if in the future the target posts permalink is changed then this short url will still work. So to that end we're going to use url_to_postid() to get the ID of the target post to past into get_permalink().
                $post_id = url_to_postid($legacy_url);
                $target = get_permalink($post_id);
                // This will add the ID of the short url post to the target post so that the get_shortlink function will work. It will only do so once bc it checks for unique existence.
                add_post_meta($post_id, 'post_short_url_target', '' . $post->ID . '', true);
            } else {
                $target = $legacy_url;
            }
        } elseif (get_post_meta($post->ID, 'url_redirect_target', true)) {
            $target = get_post_meta($post->ID, 'url_redirect_target', true);
        } elseif (get_post_meta($post->ID, 'post_redirect_target', true)) {
            $target = get_permalink(get_post_meta($post->ID, 'post_redirect_target', true));
        } else {
            $target = get_bloginfo('url');
        }
        wp_redirect($target);
        exit;
        echo '<!--Short URL Away-->';
    }
}
開發者ID:amprog,項目名稱:cap-short-urls,代碼行數:35,代碼來源:cap-url-shortener.php

示例2: get_top_pages

 public static function get_top_pages($range = 7, $amount = 20, $post_type = 'post')
 {
     $cache_key = $post_type . '-' . $range . '-' . $amount;
     if (false === ($posts = self::get_cache_value($cache_key, 'piwik_most_viewed'))) {
         $parameters = array('period' => 'range', 'date' => date('Y-m-d', strtotime('-' . $range . ' day')) . ',' . date('Y-m-d', strtotime('+1 day')), 'flat' => 1, 'filter_limit' => $amount + 20, 'filter_sort_order' => 'DESC', 'filter_sort_column' => 'nb_hits');
         $data = self::request('Actions.getPageUrls', $parameters);
         $posts = array();
         if (!is_wp_error($data) && !is_object($data)) {
             foreach ($data as $item) {
                 $post_id = url_to_postid($item['url']);
                 if ($post_id) {
                     $post = get_post($post_id);
                     if ($post->post_type == $post_type) {
                         $posts[] = $post_id;
                     }
                 }
                 if (count($posts) >= $amount) {
                     break;
                 }
             }
         }
         self::set_cache_value($cache_key, $posts, 'piwik_most_viewed', self::$timeout);
     }
     return $posts;
 }
開發者ID:markoheijnen,項目名稱:wp-piwik-more-stats,代碼行數:25,代碼來源:api.php

示例3: get_entries

 function get_entries($process_comment_func = NULL)
 {
     if (function_exists('set_magic_quotes_runtime')) {
         set_magic_quotes_runtime(0);
     }
     $xml = simplexml_load_file('compress.zlib://' . $this->file);
     // simple "are we a disqus export?" check
     if (!$xml || $xml->getName() !== 'disqus') {
         return false;
     }
     foreach ($xml->thread as $thread) {
         $attributes = $thread->attributes('dsq', true);
         $threadid = (int) $attributes['id'];
         $link = (string) $thread->link;
         if (empty($this->thread_to_post_id[$threadid])) {
             if (trailingslashit($link) == trailingslashit(get_option('siteurl'))) {
                 $this->thread_to_post_id[$threadid] = (int) get_option('page_on_front');
             } else {
                 $this->thread_to_post_id[$threadid] = url_to_postid($link);
                 // echo "<li>URL to postid: <code>", $link, "</code> - <code>", $this->thread_to_post_id[$threadid], "</code></li>";
             }
         }
     }
     if ($process_comment_func) {
         foreach ($xml->post as $comment) {
             call_user_func($process_comment_func, $comment);
         }
     }
     return true;
 }
開發者ID:kemayo,項目名稱:wp-disqus-importer,代碼行數:30,代碼來源:disqus-importer.php

示例4: build

 /**
  * Build object from posts
  *
  * @param String $posts of HTML to parse
  *
  * @return Mixed collection of posts
  */
 public static function build($posts)
 {
     $collection = [];
     $document = new \DOMDocument();
     $document->loadHTML($posts);
     $iterator = 0;
     $articles = $document->getElementsByTagName("li");
     foreach ($articles as $article) {
         $post = new \StdClass();
         $links = $article->getElementsByTagName("a");
         $images = $article->getElementsByTagName("img");
         $excerpts = $article->getElementsByTagName("small");
         foreach ($links as $link) {
             if (0 == $iterator % 2) {
                 $iterator++;
                 continue;
             }
             $iterator++;
             $post->link = $link->getAttributeNode('href')->value;
             $post->title = $link->textContent;
             $post->category = get_the_category(url_to_postid($post->link))[0]->name;
         }
         foreach ($images as $image) {
             $post->image = $image->getAttributeNode('src')->value;
         }
         foreach ($excerpts as $excerpt) {
             $post->excerpt = $excerpt->textContent;
         }
         $collection[] = $post;
     }
     return $collection;
 }
開發者ID:jsoningram,項目名稱:offgrid-framework,代碼行數:39,代碼來源:FactoryRelated.php

示例5: _getPostIdsByConfig

 protected static function _getPostIdsByConfig($key, $type)
 {
     if (!$key) {
         $key = self::getCurrentPageKey();
     }
     $cid = $key . $type;
     if (isset(self::$idsCache[$cid])) {
         return self::$idsCache[$cid];
     }
     $option = self::getOption($key);
     if (!isset($option[$type]) || !$option[$type]) {
         return array();
     }
     $post_ids = array();
     date_default_timezone_set('America/Sao_Paulo');
     /*Realiza  busca de posts no vetor de posts destacados*/
     foreach ($option[$type] as $post) {
         /*Não exibe posts expirados*/
         if ($post['data_expiracao'] == "" || !(strtotime($post['data_expiracao']) < strtotime(date('d/m/Y H:i', time())))) {
             $url = trim($post['url']);
             $post_id = url_to_postid($url);
             if ($post_id) {
                 $post_ids[] = $post_id;
             }
         }
     }
     self::$idsCache[$cid] = $post_ids;
     return $post_ids;
 }
開發者ID:hacklabr,項目名稱:cultural,代碼行數:29,代碼來源:destaques.php

示例6: heib_get_post

function heib_get_post()
{
    global $heib__Response;
    if (!is_null($heib__Response) && is_a($heib__Response, 'HEIBResponse')) {
        $query = $heib__Response->query();
        $contextUrl = isset($query['contextUrl']) ? $query['contextUrl'] : '';
        $contextUrl = stripslashes($contextUrl);
        if ($contextUrl !== '') {
            if ($postId = url_to_postid($contextUrl)) {
                $post = get_post($postId);
                //setup the current post
                setup_postdata($GLOBALS['post'] =& $post);
                return $post;
            }
        } else {
            //no contextUrl is provide, return a random post a example
            $post = query_posts('orderby=rand&showposts=1');
            if ($post) {
                //setup the current post
                setup_postdata($GLOBALS['post'] =& $post[0]);
            }
            return $post ? $post[0] : null;
        }
    }
    //no post found
    return null;
}
開發者ID:hungtran0203,項目名稱:he-ib,代碼行數:27,代碼來源:post.php

示例7: check_for_cache

 function check_for_cache()
 {
     if (isset($_GET['force_skip_caching'])) {
         return;
     }
     // only for is_single()
     $postID = url_to_postid("http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
     if (is_numeric($postID) == false) {
         return;
     }
     $cacheDirectory = dirname(__FILE__) . "/files/";
     if (file_exists($cacheDirectory . "{$postID}.html") == true) {
         $postContent = file_get_contents($cacheDirectory . "{$postID}.html");
         echo $postContent;
         exit;
     } else {
         $url = get_site_url() . "?p={$postID}&force_skip_caching=true";
         try {
             $postContent = $this->doFetchUrl($url);
             $cacheFile = fopen($cacheDirectory . "{$postID}.html", "w");
             fwrite($cacheFile, $postContent);
             $this->doRedirect($cacheDirectory, $postID);
         } catch (Exception $e) {
             return;
         }
     }
 }
開發者ID:MythicAngel,項目名稱:Wordpress-Solutions,代碼行數:27,代碼來源:index.php

示例8: redirect

 public function redirect()
 {
     // Keyword to check for in URL
     $keyword = urlencode(WPUltimateRecipe::option('print_template_keyword', 'print'));
     if (strlen($keyword) <= 0) {
         $keyword = 'print';
     }
     // Current URL
     $schema = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://';
     $url = $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     // Check if URL ends with /print
     preg_match("/^(.*?)\\/{$keyword}()\$/", $url, $url_data);
     if (empty($url_data)) {
         // Check if URL ends with /print/parameters
         preg_match("/^(.*?)\\/{$keyword}\\/(.*?)\$/", $url, $url_data);
     }
     if (isset($url_data[1])) {
         $post_id = url_to_postid($url_data[1]);
         $post = get_post($post_id);
         if ($post_id == 0) {
             // Check for plain permalinks
             $slug = substr(strrchr($url_data[1], '='), 1);
             if ($slug) {
                 $post = get_page_by_path($slug, OBJECT, WPURP_POST_TYPE);
             }
         }
         if ($post && $post->post_type == WPURP_POST_TYPE) {
             $recipe = new WPURP_Recipe($post);
             $this->print_recipe($recipe, $url_data[2]);
             exit;
         }
     }
 }
開發者ID:robertoperata,項目名稱:bbqverona.com,代碼行數:33,代碼來源:print.php

示例9: Record_User_Event

function Record_User_Event()
{
    $Path = ABSPATH . 'wp-load.php';
    include_once $Path;
    global $wpdb;
    global $ewd_feup_user_events_table_name;
    $User_ID = $_POST['User_ID'];
    $Event_Value = $_POST['Target'];
    $Event_Location = $_POST['Location'];
    $Event_Location_ID = url_to_postid($Event_Location);
    if ($Event_Location_ID != 0) {
        $Event_Location_Title = get_the_title($Event_Location_ID);
    } else {
        $Event_Location_Title = $Event_Location;
    }
    $Event_Type = Get_Event_Type($Event_Value);
    $Event_Target_ID = url_to_postid($Event_Value);
    if ($Event_Target_ID == 0) {
        $Event_Target_ID = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid=%s", $Event_Value));
    }
    if ($Event_Target_ID != 0) {
        $Event_Target_Title = get_the_title($Event_Target_ID);
    } else {
        $Event_Target_Title = $Event_Value;
    }
    Add_User_Event($User_ID, $Event_Type, $Event_Location, $Event_Location_ID, $Event_Location_Title, $Event_Value, $Event_Target_ID, $Event_Target_Title);
}
開發者ID:otkinsey,項目名稱:wp-nsds,代碼行數:27,代碼來源:Process_Ajax.php

示例10: get_oembed_response

 /**
  * Callback for our API endpoint.
  *
  * Returns the JSON object for the post.
  *
  * @param WP_REST_Request $request Full details about the request.
  *
  * @return WP_Error|WP_REST_Response
  */
 public function get_oembed_response(WP_REST_Request $request)
 {
     $post_id = url_to_postid($request['url']);
     /**
      * Filter the determined post id.
      *
      * @param int    $post_id The post ID.
      * @param string $url     The requestd URL.
      */
     $post_id = apply_filters('rest_oembed_request_post_id', $post_id, $request['url']);
     if (0 === $post_id) {
         return new WP_Error('rest_oembed_invalid_url', __('Invalid URL.', 'oembed-api'), array('status' => 404));
     }
     // Todo: Perhaps just default to json if something invalid is provided.
     if (!in_array($request['format'], array('json', 'xml'))) {
         return new WP_Error('rest_oembed_invalid_format', __('Invalid format.', 'oembed-api'), array('status' => 501));
     }
     /**
      * Current post object.
      *
      * @var WP_Post $post
      */
     $post = get_post($post_id);
     /**
      * User object for the post author.
      *
      * @var WP_User $author
      */
     $author = get_userdata($post->post_author);
     /**
      * Filter the allowed minimum width for the oEmbed response.
      *
      * @param int $width The minimum width. Defaults to 200.
      */
     $minwidth = apply_filters('rest_oembed_minwidth', 200);
     /**
      * Filter the allowed maximum width for the oEmbed response.
      *
      * @param int $width The maximum width. Defaults to 600.
      */
     $maxwidth = apply_filters('rest_oembed_maxwidth', 600);
     $width = $request['maxwidth'];
     if ($width < $minwidth) {
         $width = $minwidth;
     } else {
         if ($width > $maxwidth) {
             $width = $maxwidth;
         }
     }
     // Todo: this shouldn't be hardcoded.
     $height = ceil($width / 16 * 9);
     /**
      * Filters the oEmbed response data.
      *
      * @param array $data The response data.
      */
     $data = apply_filters('rest_oembed_response_data', array('version' => '1.0', 'provider_name' => get_bloginfo('name'), 'provider_url' => get_home_url(), 'author_name' => $author->display_name, 'author_url' => get_author_posts_url($author->ID, $author->user_nicename), 'title' => $post->post_title, 'type' => 'rich', 'width' => $width, 'height' => $height, 'html' => get_post_embed_html($post, $width, $height)));
     return $data;
 }
開發者ID:pfefferle,項目名稱:oEmbed-API,代碼行數:68,代碼來源:endpoint.php

示例11: url_to_blog_card_tag

 function url_to_blog_card_tag($url)
 {
     if (!$url) {
         return;
     }
     $url = strip_tags($url);
     //URL
     $id = url_to_postid($url);
     //IDを取得(URLから投稿ID変換)
     if (!$id) {
         return;
     }
     //IDを取得できない場合はループを飛ばす
     global $post;
     $post_id = get_post($id);
     setup_postdata($post_id);
     $exce = $post_id->post_excerpt;
     $title = $post_id->post_title;
     //タイトルの取得
     $date = mysql2date('Y-m-d H:i', $post_id->post_date);
     //投稿日の取得
     $excerpt = get_content_excerpt($post_id->post_content, get_excerpt_length());
     //抜粋の取得
     if (is_wordpress_excerpt() && $exce) {
         //Wordpress固有の抜粋のとき
         $excerpt = $exce;
     }
     //新しいタブで開く場合
     $target = is_blog_card_target_blank() ? ' target="_blank"' : '';
     //$hatebu_url = preg_replace('/^https?:\/\//i', '', $url);
     //はてブを表示する場合
     $hatebu_tag = is_blog_card_hatena_visible() ? '<div class="blog-card-hatebu"><a href="//b.hatena.ne.jp/entry/' . $url . '"' . $target . '><img src="//b.hatena.ne.jp/entry/image/' . $url . '" alt="はてブ數" /></a></div>' : '';
     //サイトロゴを表示する場合
     $favicon_tag = '';
     if (is_favicon_enable() && get_the_favicon_url()) {
         //ファビコンが有効か確認
         //ファビコンをイメージたいのでそのまま表示する
         //$favicon_tag = '<span class="blog-card-favicon"><img src="'.get_the_favicon_url().'" class="blog-card-favicon-img" alt="ファビコン" /></span>';
         //はてなファビコンAPIを利用する
         //$favicon_tag = '<span class="blog-card-favicon"><img src="http://favicon.st-hatena.com/?url='.site_url().'" class="blog-card-favicon-img" alt="ファビコン" /></span>';
         //GoogleファビコンAPIを利用する
         //http://www.google.com/s2/favicons?domain=nelog.jp
         $favicon_tag = '<span class="blog-card-favicon"><img src="http://www.google.com/s2/favicons?domain=' . get_this_site_domain() . '" class="blog-card-favicon-img" alt="ファビコン" /></span>';
     }
     $site_logo_tag = is_blog_card_site_logo_visible() ? '<div class="blog-card-site">' . $favicon_tag . '<a href="' . home_url() . '"' . $target . '>' . get_this_site_domain() . '</a></div>' : '';
     $date_tag = '';
     if (is_blog_card_date_visible()) {
         $date_tag = '<div class="blog-card-date">' . $date . '</div>';
     }
     //サムネイルの取得(要100×100のサムネイル設定)
     $thumbnail = get_the_post_thumbnail($id, 'thumb100', array('class' => 'blog-card-thumb-image', 'alt' => $title));
     if (!$thumbnail) {
         //サムネイルが存在しない場合
         $thumbnail = '<img src="' . get_template_directory_uri() . '/images/no-image.png" alt="' . $title . '" class="blog-card-thumb-image" />';
     }
     //取得した情報からブログカードのHTMLタグを作成
     $tag = '<div class="blog-card internal-blog-card"><div class="blog-card-thumbnail"><a href="' . $url . '" class="blog-card-thumbnail-link"' . $target . '>' . $thumbnail . '</a></div><div class="blog-card-content"><div class="blog-card-title"><a href="' . $url . '" class="blog-card-title-link"' . $target . '>' . $title . '</a></div><div class="blog-card-excerpt">' . $excerpt . '</div></div><div class="blog-card-footer">' . $site_logo_tag . $hatebu_tag . $date_tag . '</div></div>';
     return $tag;
 }
開發者ID:musashi0128,項目名稱:wordpress,代碼行數:59,代碼來源:blog-card.php

示例12: bayfront_header_style

function bayfront_header_style()
{
    $header_image = get_header_image();
    if (empty($header_image)) {
        return;
    }
    ?>
<style type="text/css">

<?php 
    if (is_single() && get_post_type() == 'property') {
        ?>
	<?php 
        $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
        ?>
	#container-wrap-header {
		background: none;
	}
<?php 
    } else {
        ?>
	<?php 
        // Get post id
        $url = explode('?', 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
        $ID = url_to_postid($url[0]);
        $page_template = get_post_meta(get_the_ID(), '_wp_page_template', true);
        ?>
	
	
	<?php 
        if ($page_template == 'page-templates/properties-subpage.php') {
            ?>
		<?php 
            $url = wp_get_attachment_url(get_post_thumbnail_id($post_id));
            ?>
		#container-wrap-header {
			background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0)), url(<?php 
            echo $url;
            ?>
) no-repeat center;
			background-size: cover;
		}
	<?php 
        } else {
            ?>
		#container-wrap-header {
			background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0)), url(<?php 
            header_image();
            ?>
) no-repeat center;
			background-size: cover;
		}
	<?php 
        }
    }
    ?>
</style>
<?php 
}
開發者ID:phucanh92,項目名稱:vietlong,代碼行數:59,代碼來源:functions.php

示例13: op_remove_enigmapro_js

function op_remove_enigmapro_js()
{
    $checkIfLEPage = get_post_meta(url_to_postid("http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']), '_optimizepress_pagebuilder', true);
    if ($checkIfLEPage || $_GET['page'] == 'optimizepress-page-builder' || defined('OP_LIVEEDITOR')) {
        remove_action('wp_enqueue_scripts', 'weblizar_scripts', 10);
        remove_action('wp_footer', 'weblizar_footer_js', 10);
    }
}
開發者ID:OptimizePress,項目名稱:op-enigma-pro-fix,代碼行數:8,代碼來源:op-enigma-pro-fix.php

示例14: op_allow_bbforum

 function op_allow_bbforum()
 {
     $forumPage = get_post(url_to_postid("http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
     if ($forumPage->post_type == 'forum') {
         op_update_option('blog_enabled', 'Y');
         op_update_option('installed', 'Y');
     }
 }
開發者ID:OptimizePress,項目名稱:op-bbpress-fix,代碼行數:8,代碼來源:op-bbpress-fix.php

示例15: flush

 /**
  * Clear something from the cache
  *
  * @param array $args
  * @param array $vars
  */
 function flush($args = array(), $vars = array())
 {
     if (function_exists('w3tc_pgcache_flush')) {
         $args = array_unique($args);
         do {
             $cache_type = array_shift($args);
             switch ($cache_type) {
                 case 'db':
                 case 'database':
                     if (w3tc_dbcache_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'minify':
                     if (w3tc_minify_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'object':
                     if (w3tc_objectcache_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'post':
                 default:
                     if (isset($vars['post_id'])) {
                         if (is_numeric($vars['post_id'])) {
                             w3tc_pgcache_flush_post($vars['post_id']);
                         } else {
                             WP_CLI::error('This is not a valid post id.');
                         }
                         w3tc_pgcache_flush_post($vars['post_id']);
                     } elseif (isset($vars['permalink'])) {
                         $id = url_to_postid($vars['permalink']);
                         if (is_numeric($id)) {
                             w3tc_pgcache_flush_post($id);
                         } else {
                             WP_CLI::error('There is no post with this permalink.');
                         }
                     } else {
                         if (isset($flushed_page_cache) && $flushed_page_cache) {
                             break;
                         }
                         $flushed_page_cache = true;
                         w3tc_pgcache_flush();
                     }
             }
         } while (!empty($args));
     } else {
         WP_CLI::error('The W3 Total Cache could not be found, is it installed?');
     }
 }
開發者ID:roelven,項目名稱:wp-cli,代碼行數:64,代碼來源:total-cache.php


注:本文中的url_to_postid函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。