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


PHP pll_get_post函数代码示例

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


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

示例1: block_shortcode

function block_shortcode($atts, $content = null)
{
    extract(shortcode_atts(array('id' => ''), $atts));
    // get Page ID by slug
    global $wpdb, $post;
    $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_name = '{$id}'");
    // Polylang support
    if (function_exists('pll_get_post') && pll_get_post($post_id)) {
        $lang_id = pll_get_post($post_id);
        if ($lang_id) {
            $post_id = $lang_id;
        }
    }
    // WPML Support
    if (function_exists('icl_object_id')) {
        $lang_id = icl_object_id($post_id, 'blocks', false, ICL_LANGUAGE_CODE);
        if ($lang_id) {
            $post_id = $lang_id;
        }
    }
    $permalink = get_permalink($post_id);
    if ($post_id) {
        $html = get_post_field('post_content', $post_id);
        // add edit link for admins
        if (current_user_can('edit_pages')) {
            $edit_link = get_edit_post_link($post_id);
            $html = '<div id="block-' . $id . '" class="ux_block"><a class="edit-link" href="' . $edit_link . '&preview_url=' . $post->ID . '">Edit Block</a>' . $html . '</div>';
        }
        $html = do_shortcode($html);
    } else {
        $html = '<p><mark>Block <b>"' . $id . '"</b> not found!</mark></p>';
    }
    return $html;
}
开发者ID:sialaweb,项目名称:Euroimpacto-theme,代码行数:34,代码来源:blocks.php

示例2: get_slug_pll

 public static function get_slug_pll($slug, $type)
 {
     $id = self::get_id_by_slug($slug, $type);
     $id = pll_get_post($id, pll_current_language());
     $data = get_post($id, ARRAY_A);
     return $data['post_name'];
 }
开发者ID:gnribeiro,项目名称:turim,代码行数:7,代码来源:Helper.php

示例3: footsy

function footsy()
{
    global $popupBoxen;
    echo $popupBoxen;
    if (class_exists('PLL_Base')) {
        echo '<span id="pylangswitcher">';
        //  echo '<li><a id="notice-trans" href="#">notice! (08-30)</a></li>';
        // these are the publicly-available languages
        foreach (unserialize(PRODUCTION_LANGUAGES) as $lang) {
            if ($lang != pll_current_language()) {
                echo '<li><a href="' . get_permalink(pll_get_post(get_the_ID(), $lang)) . '">' . $lang . '</a></li>';
            }
        }
        // these are the ones in development
        if (userIsAdmin() || userIsTranslator() || userIsAssistant()) {
            foreach (unserialize(DEVELOPMENT_LANGUAGES) as $lang) {
                if ($lang != pll_current_language()) {
                    echo '<li><a href="' . get_permalink(pll_get_post(get_the_ID(), $lang)) . '">' . $lang . '</a></li>';
                }
            }
        }
        // old method:  echo pll_the_languages(array('echo'=>0,'display_names_as' => 'slug','hide_current' => 1));
        if (userIsAdmin() || userIsTranslator() || userIsAssistant()) {
            echo '<li><a href="' . admin_url('edit.php?post_type=page') . '">' . __t('Editor') . '</a></li>';
        }
        echo '</span>';
    }
}
开发者ID:joostrijneveld,项目名称:cscircles-wp-content,代码行数:28,代码来源:plugin-hooks.php

示例4: tptn_object_id_cur_lang

/**
 * Fetch the post of the correct language.
 *
 * @since	2.1.0
 *
 * @param	$post_id	Post ID
 */
function tptn_object_id_cur_lang($post_id)
{
    $return_original_if_missing = false;
    /**
     * Filter to modify if the original language ID is returned.
     *
     * @since	2.2.3
     *
     * @param	bool	$return_original_if_missing
     * @param	int	$post_id	Post ID
     */
    $return_original_if_missing = apply_filters('tptn_wpml_return_original', $return_original_if_missing, $post_id);
    if (function_exists('pll_get_post')) {
        $post_id = pll_get_post($post_id);
    } elseif (function_exists('wpml_object_id_filter')) {
        $post_id = wpml_object_id_filter($post_id, 'any', $return_original_if_missing);
    } elseif (function_exists('icl_object_id')) {
        $post_id = icl_object_id($post_id, 'any', $return_original_if_missing);
    }
    /**
     * Filters object ID for current language (WPML).
     *
     * @since	2.1.0
     *
     * @param	int	$post_id	Post ID
     */
    return apply_filters('tptn_object_id_cur_lang', $post_id);
}
开发者ID:designomx,项目名称:DMXFrmwrk,代码行数:35,代码来源:l10n.php

示例5: getProductTranslationByObject

 /**
  * Get product translation by object
  *
  * @param \WC_Product $product the product to use to retirve translation
  * @param string      $slug    the language slug
  *
  * @return \WC_Product product translation or same prodcut if translaion not found
  */
 public static function getProductTranslationByObject(\WC_Product $product, $slug = '')
 {
     $productTranslationID = pll_get_post($product->id, $slug);
     if ($productTranslationID) {
         $translated = wc_get_product($productTranslationID);
         $product = $translated ? $translated : $product;
     }
     return $product;
 }
开发者ID:Frost-Bite,项目名称:woo-poly-integration,代码行数:17,代码来源:Utilities.php

示例6: getLoginRedirectPermalink

 /**
  * Find the correct login redirect permalink
  *
  * @param string $to redirect url
  *
  * @return string redirect url
  */
 public function getLoginRedirectPermalink($to)
 {
     $ID = url_to_postid($to);
     $translatedID = pll_get_post($ID);
     if ($translatedID) {
         return get_permalink($translatedID);
     }
     return $to;
 }
开发者ID:Frost-Bite,项目名称:woo-poly-integration,代码行数:16,代码来源:Login.php

示例7: replace_product_listing_id

/**
 * Replaces product listing IDs for different language
 * @param int $listing_id
 * @return int
 */
function replace_product_listing_id($listing_id)
{
    if (function_exists('pll_get_post')) {
        $listing_id = pll_get_post($listing_id);
    }
    if (function_exists('icl_object_id')) {
        $listing_id = icl_object_id($listing_id, 'al_product', true);
    }
    return $listing_id;
}
开发者ID:jazzindizzin,项目名称:Quality-Timber-Doors,代码行数:15,代码来源:multilingual.php

示例8: pll_after_post_column

 public static function pll_after_post_column($column, $post_id)
 {
     if (false === strpos($column, 'language_')) {
         return;
     }
     $language = Pll()->model->get_language(substr($column, 9));
     $translation_id = pll_get_post($post_id, $language->slug);
     if (get_post_meta($translation_id, Endpoints::TRAPP_META_TRANSLATED, true)) {
         echo '</span>';
     }
 }
开发者ID:benjaminmedia,项目名称:wp-trapp,代码行数:11,代码来源:Columns.php

示例9: translateGallery

 /**
  * Translate product gallery
  *
  * @param array $IDS current attachment IDS
  *
  * @return array translated attachment IDS
  */
 public function translateGallery(array $IDS)
 {
     $translations = array();
     foreach ($IDS as $ID) {
         $tr = pll_get_post($ID);
         if ($tr) {
             $translations[] = $tr;
             continue;
         }
         $translations[] = $ID;
     }
     return $translations;
 }
开发者ID:Frost-Bite,项目名称:woo-poly-integration,代码行数:20,代码来源:Media.php

示例10: getTranslatedPosts

 /**
  * Get an array with all available translations for a given post
  *
  * @param int $postID
  * @return array Indexed array with as key the language code, and as value the post id
  */
 public function getTranslatedPosts($postID)
 {
     $languages = pll_the_languages(array('raw' => 1));
     $result = array();
     foreach ($languages as $lang) {
         $lang = $lang['slug'];
         $transPostID = pll_get_post($postID, $lang);
         if (is_int($transPostID) && $transPostID !== $postID) {
             $result[$lang] = $transPostID;
         }
     }
     return $result;
 }
开发者ID:nextbuzz,项目名称:buzz-seo,代码行数:19,代码来源:Polylang.php

示例11: widget

 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     // Prepare data for mustache template
     $page_id = absint($instance['page_id']);
     /**
      * Support for the Polylang plugin.
      * https://proteusthemes.zendesk.com/agent/tickets/5175
      * https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/#pll_get_post
      */
     if (function_exists('pll_get_post')) {
         $page_id = pll_get_post($page_id);
     }
     $instance['layout'] = sanitize_key($instance['layout']);
     $instance['read_more_text'] = empty($instance['read_more_text']) ? esc_html__('Read more', 'proteuswidgets') : sanitize_text_field($instance['read_more_text']);
     $thumbnail_size = 'inline' === $instance['layout'] ? 'pw-inline' : 'pw-page-box';
     // Get basic page info
     if ($page_id) {
         $page = (array) get_post($page_id);
     }
     // Prepare the excerpt text
     $excerpt = !empty($page['post_excerpt']) ? $page['post_excerpt'] : $page['post_content'];
     if ('inline' === $instance['layout'] && strlen($excerpt) > $this->excerpt_lengths['inline_excerpt']) {
         $strpos = strpos($excerpt, ' ', $this->excerpt_lengths['inline_excerpt']);
         $excerpt = false !== $strpos ? substr($excerpt, 0, $strpos) . ' &hellip;' : $excerpt;
     } elseif (strlen($excerpt) > $this->excerpt_lengths['block_excerpt']) {
         $strpos = strpos($excerpt, ' ', $this->excerpt_lengths['block_excerpt']);
         $excerpt = false !== $strpos ? substr($excerpt, 0, $strpos) . ' &hellip;' : $excerpt;
     }
     $page['post_excerpt'] = sanitize_text_field($excerpt);
     $page['link'] = get_permalink($page_id);
     $page['thumbnail'] = get_the_post_thumbnail($page_id, $thumbnail_size);
     if ('block' === $instance['layout']) {
         $attachment_image_id = get_post_thumbnail_id($page_id);
         $attachment_image_data = wp_get_attachment_image_src($attachment_image_id, 'pw-page-box');
         $page['image_url'] = $attachment_image_data[0];
         $page['image_width'] = $attachment_image_data[1];
         $page['image_height'] = $attachment_image_data[2];
         $page['srcset'] = PW_Functions::get_attachment_image_srcs($attachment_image_id, array('pw-page-box', 'full'));
     }
     // Mustache widget-featured-page template rendering
     echo $this->mustache->render(apply_filters('pw/widget_featured_page_view', 'widget-featured-page'), array('args' => $args, 'page' => $page, 'instance' => $instance, 'block' => 'block' === $instance['layout']));
 }
开发者ID:proteusthemes,项目名称:proteuswidgets,代码行数:50,代码来源:widget-featured-page.php

示例12: pre_get_posts

 public function pre_get_posts($query)
 {
     global $wpdb;
     $qv =& $query->query_vars;
     if ($query->is_main_query() || !empty($qv['lang']) || !empty($qv['post_type']) && !$this->model->is_translated_post_type($qv['post_type'])) {
         return;
     }
     $sign = create_function('$n', 'return $n > 0 ? 1 : ($n < 0 ? -1 : 0);');
     // /!\ always keep untranslated as is
     // term ids separated by a comma
     $arr = array();
     if (!empty($qv['cat'])) {
         foreach (explode(',', $qv['cat']) as $cat) {
             $arr[] = ($tr = $sign($cat) * pll_get_term(abs($cat))) ? $tr : $cat;
         }
         $qv['cat'] = implode(',', $arr);
     }
     // category_name
     $arr = array();
     if (!empty($qv['category_name'])) {
         foreach (explode(',', $qv['category_name']) as $slug) {
             $arr[] = ($cat = get_category_by_slug($slug)) && ($tr_id = pll_get_term($cat->term_id)) && !is_wp_error($tr = get_category($tr_id)) ? $tr->slug : $slug;
         }
         $qv['category_name'] = implode(',', $arr);
     }
     // array of term ids
     foreach (array('category__and', 'category__in', 'category__not_in', 'tag__and', 'tag__in', 'tag__not_in') as $key) {
         $arr = array();
         if (!empty($qv[$key])) {
             foreach ($qv[$key] as $cat) {
                 $arr[] = ($tr = pll_get_term($cat)) ? $tr : $cat;
             }
             $qv[$key] = $arr;
         }
     }
     // tag
     $arr = array();
     if (!empty($qv['tag'])) {
         $sep = strpos($qv['tag'], ',') !== false ? ',' : '+';
         // two possible separators for tag slugs
         foreach (explode($sep, $qv['tag']) as $slug) {
             $arr[] = ($tag = get_term_by('slug', $slug, 'post_tag')) && ($tr_id = pll_get_term($tag->term_id)) && !is_wp_error($tr = get_tag($tr_id)) ? $tr->slug : $slug;
         }
         $qv['tag'] = implode($sep, $arr);
     }
     // tag_id can only take one id
     if (!empty($qv['tag_id']) && ($tr_id = pll_get_term($qv['tag_id']))) {
         $qv['tag_id'] = $tr_id;
     }
     // array of tag slugs
     foreach (array('tag_slug__and', 'tag_slug__in') as $key) {
         $arr = array();
         if (!empty($qv[$key])) {
             foreach ($qv[$key] as $slug) {
                 $arr[] = ($tag = get_term_by('slug', $slug, 'post_tag')) && ($tr_id = pll_get_term($tag->term_id)) && !is_wp_error($tr = get_tag($tr_id)) ? $tr->slug : $slug;
             }
             $qv[$key] = $arr;
         }
     }
     // custom taxonomies
     // according to codex, this type of query is deprecated as of WP 3.1 but it does not appear in WP 3.5 source code
     foreach (array_intersect($this->model->get_translated_taxonomies(), get_taxonomies(array('_builtin' => false))) as $taxonomy) {
         $tax = get_taxonomy($taxonomy);
         $arr = array();
         if (!empty($qv[$tax->query_var])) {
             $sep = strpos($qv[$tax->query_var], ',') !== false ? ',' : '+';
             // two possible separators
             foreach (explode($sep, $qv[$tax->query_var]) as $slug) {
                 $arr[] = ($tag = get_term_by('slug', $slug, $taxonomy)) && ($tr_id = pll_get_term($tag->term_id)) && !is_wp_error($tr = get_term($tr_id, $taxonomy)) ? $tr->slug : $slug;
             }
             $qv[$tax->query_var] = implode($sep, $arr);
         }
     }
     // tax_query since WP 3.1
     if (!empty($qv['tax_query']) && is_array($qv['tax_query'])) {
         $qv['tax_query'] = $this->translate_tax_query_recursive($qv['tax_query']);
     }
     // p, page_id, post_parent can only take one id
     foreach (array('p', 'page_id', 'post_parent') as $key) {
         if (!empty($qv[$key]) && ($tr_id = pll_get_post($qv[$key]))) {
             $qv[$key] = $tr_id;
         }
     }
     // name, pagename can only take one slug
     foreach (array('name', 'pagename') as $key) {
         if (!empty($qv[$key])) {
             // no function to get post by name except get_posts itself
             $post_type = empty($qv['post_type']) ? 'post' : $qv['post_type'];
             $id = $wpdb->get_var($wpdb->prepare("SELECT ID from {$wpdb->posts} WHERE post_type=%s AND post_name=%s", $post_type, $qv[$key]));
             $qv[$key] = $id && ($tr_id = pll_get_post($id)) && ($tr = get_post($tr_id)) ? $tr->post_name : $qv[$key];
         }
     }
     // array of post ids
     // post_parent__in & post_parent__not_in since WP 3.6
     foreach (array('post__in', 'post__not_in', 'post_parent__in', 'post_parent__not_in') as $key) {
         $arr = array();
         if (!empty($qv[$key])) {
             // post__in used by the 2 functions below
             // useless to filter them as output is already in the right language and would result in performance loss
             foreach (debug_backtrace() as $trace) {
//.........这里部分代码省略.........
开发者ID:WordPressArt,项目名称:conisia,代码行数:101,代码来源:frontend-auto-translate.php

示例13: get_items

 /**
  * Filter the navigation menu items being returned.
  *
  * @param  array   $items  An array of menu item post objects.
  * @param  object  $menu   The menu object.
  * @param  array   $args   An array of arguments used to retrieve menu item objects.
  * @return array   $items
  */
 public static function get_items($items, $menu, $args)
 {
     foreach ($items as &$item) {
         if ($item->type === static::$obj_archive) {
             $obj_type = get_post_type_object($item->object);
             if (!$obj_type) {
                 continue;
             }
             if ('post' === $obj_type->name) {
                 $page_id = get_option('page_for_posts');
                 if (!empty($page_id)) {
                     $item->title = get_the_title($page_id);
                 }
             } elseif (!empty($obj_type->labels->page_for_items_setting)) {
                 $options = get_option('boilerplate', []);
                 $setting = $obj_type->labels->page_for_items_setting;
                 if (!empty($options[$setting])) {
                     $item->title = get_the_title(pll_get_post($options[$setting]));
                 }
             }
             $item->url = get_post_type_archive_link($item->object);
             /**
              * @deprecated The _wp_menu_item_classes_by_context() function
              *             resets this property.
              */
             /*
             				if ( get_query_var( 'post_type' ) == $item->object ) {
             					$item->classes[] = 'current-menu-item';
             					$item->current = true;
             				}
             */
         }
     }
     return $items;
 }
开发者ID:locomotivemtl,项目名称:wordpress-boilerplate,代码行数:43,代码来源:nav-menus.php

示例14: translateShopUrl

 /**
  * Translate the shop page name in the given shop url.
  *
  * @param string $url      complete url
  * @param string $language the current language
  *
  * @return string translated url
  */
 public function translateShopUrl($url, $language)
 {
     $result = $url;
     if (!is_post_type_archive('product')) {
         return $result;
     }
     $shopPageID = get_option('woocommerce_shop_page_id');
     $shopPage = get_post($shopPageID);
     if ($shopPage) {
         $shopPageTranslatedID = pll_get_post($shopPageID, $language);
         $shopPageTranslation = get_post($shopPageTranslatedID);
         if ($shopPageTranslation) {
             $result = str_replace($shopPage->post_name, $shopPageTranslation->post_name, $url);
         }
     }
     return $result;
 }
开发者ID:hyyan,项目名称:woo-poly-integration,代码行数:25,代码来源:Pages.php

示例15: pll_woocommerce_get_page_id

 function pll_woocommerce_get_page_id($id)
 {
     return pll_get_post($id);
     // translate the page to current language
 }
开发者ID:qRoC,项目名称:woocommerce-polylang-integration,代码行数:5,代码来源:woocommerce-polylang-integration.php


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