本文整理汇总了PHP中get_page_by_path函数的典型用法代码示例。如果您正苦于以下问题:PHP get_page_by_path函数的具体用法?PHP get_page_by_path怎么用?PHP get_page_by_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_page_by_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: url_shortcode
function url_shortcode($atts)
{
// Attributes
extract(shortcode_atts(array('type' => '', 'id' => '0', 'path' => '', 'title' => '', 'action' => '', 'class' => ''), $atts));
if (!$id && !$path && !$title && !$action) {
return home_url();
} else {
$page_id = 0;
if ($id && is_numeric($id)) {
$page_id = $id;
}
if ($path != '') {
$page_id = get_page_by_path($path);
}
if ($title != '') {
$page_id = get_page_by_title($title);
}
if ($action != '') {
if ($action == 'logout') {
return wp_logout_url();
}
}
if ($page_id) {
return get_page_link($page_id);
} else {
return null;
}
}
}
示例2: by_path
/**
* Gets a WordPress® post by path; instead of by ID.
*
* @param string $path A URL path (ex: `/sample-page/`, `/sample-page`, `sample-page`).
* This also works with sub-pages (ex: `/parent-page/sub-page/`).
* Also with post type prefixes (ex: `/post/hello-world/`).
* Also with pagination (ex: `/post/hello-world/page/2`).
*
* @param array $exclude_types Optional. Defaults to `array('revision', 'nav_menu_item')`.
* We will NOT search for these post types. Pass an empty array to search all post types.
* Important to note... it is NOT possible to exclude the `attachment` type;
* because {@link \get_page_by_path()} always searches this type.
*
* @return null|\WP_Post A WP_Post object instance if found; else NULL.
*
* @throws exception If invalid types are passed through arguments list.
*
* @see http://codex.wordpress.org/Function_Reference/get_page_by_path
* NOTE: This supports MORE than just pages; even though the function name implies otherwise.
*/
public function by_path($path, $exclude_types = array('revision', 'nav_menu_item'))
{
$this->check_arg_types('string', 'array', func_get_args());
$path = trim($path, '/');
// Trim all slashes.
$path = preg_replace($this->©url->regex_wp_pagination_page(), '', $path);
if ($path && $path !== '/') {
foreach (get_post_types() as $_type) {
if (!in_array($_type, $exclude_types, TRUE)) {
$_type_slug = $_type;
// Default slug.
$_type_specs = get_post_type_object($_type);
if ($this->©array->is_not_empty($_type_specs->rewrite)) {
if ($this->©string->is_not_empty($_type_specs->rewrite['slug'])) {
$_type_slug = $_type_specs->rewrite['slug'];
}
}
if ($_path = preg_replace('/^' . preg_quote($_type_slug, '/') . '\\//', '', $path)) {
if ($post = get_page_by_path($_path, OBJECT, $_type)) {
return $post;
}
}
}
}
}
unset($_type, $_type_specs, $_type_slug);
return NULL;
// Default return value.
}
示例3: form
function form($instance)
{
$home = get_page_by_path('home');
$home_text = get_post_meta($home->ID, 'home_text_widget', true);
if (empty($home_text)) {
$home_text['home_text_title'] = __('Titel');
$home_text['home_text_body'] = '';
}
?>
<p>
<label for="home_text_title">Titel</label>
<input id="home_text_title" name="home_text_title" value="<?php
echo $home_text['home_text_title'];
?>
" style="width:100%;" />
</p>
<p>
<label for="home_text_body">Body</label>
<textarea id="home_text_body" name="home_text_body" style="width:100%;height:80px;"><?php
echo $home_text['home_text_body'];
?>
</textarea>
</p>
<?php
}
示例4: print_sibiling_pages
function print_sibiling_pages($post)
{
$slug_parts = explode('-', $post->post_name);
if (count($slug_parts) != 2) {
return;
}
$page_num = intval($slug_parts[1]);
if ($page_num <= 0) {
return;
}
echo '<div class="story-pageing">';
if ($page_num > 1) {
$back_slug = $slug_parts[0] . '-' . ($page_num - 1);
$back_page = get_posts(array('name' => $back_slug, 'post_type' => 'page'));
if (count($back_page) > 0) {
echo '<div class="story-back"><a href="' . get_permalink(get_page_by_path($back_slug)) . '">Read Previous Story</a></div>';
}
}
$next_slug = $slug_parts[0] . '-' . ($page_num + 1);
$next_page = get_posts(array('name' => $next_slug, 'post_type' => 'page'));
if (count($next_page) > 0) {
echo '<div class="story-next"><a href="' . get_permalink(get_page_by_path($next_slug)) . '">Read Next Story</a></div>';
}
echo '</div>';
}
示例5: registerUser
/**
* ユーザー登録処理
*
*/
public function registerUser()
{
// 新規ユーザーデータを取得する
$this->user = $this->clearUser();
if (isset($_POST['nonce'])) {
// エラーなら処理を中止する
if ($this->errcode = $this->_illegalInput()) {
return;
}
if ($_POST['action'] === 'confirm' && $this->_normalize()) {
// ユーザー新規登録
if (!$this->_newUser()) {
$this->errcode = 'FAILED_INSERT';
return;
}
// 登録完了メール送信
if (!$this->_sendMail()) {
$this->errcode = 'FAILED_SENDING';
return;
}
// 登録完了リダイレクト表示
$url = get_permalink(get_page_by_path(self::PAGE_THANKS));
$redirect = add_query_arg(array('action' => 'registered', 'nonce' => wp_create_nonce(__CLASS__)), $url);
wp_redirect($redirect);
exit;
}
}
}
示例6: shortcode
/**
* Creates the shortcode for the plugin.
*
* @since 2.0.0
*
* @global object $post The current post object.
*
* @param array $atts Array of shortcode attributes.
* @return string The optin output.
*/
public function shortcode($atts)
{
global $post;
$optin_id = false;
if (isset($atts['id'])) {
$optin_id = (int) $atts['id'];
} else {
if (isset($atts['slug'])) {
$optin = get_page_by_path($atts['slug'], OBJECT, 'optin');
if ($optin) {
$optin_id = $optin->ID;
}
} else {
// A custom attribute must have been passed. Allow it to be filtered to grab the optin ID from a custom source.
$optin_id = apply_filters('optin_monster_custom_optin_id', false, $atts, $post);
}
}
// Allow the optin ID to be filtered before it is stored and used to create the optin output.
$optin_id = apply_filters('optin_monster_pre_optin_id', $optin_id, $atts, $post);
// If there is no optin, do nothing.
if (!$optin_id) {
return false;
}
// If we are in a preview state, the optin needs to match the one requested, otherwise return false.
if (Optin_Monster_Output::get_instance()->is_preview()) {
if (Optin_Monster_Output::get_instance()->optin_id && Optin_Monster_Output::get_instance()->optin_id !== $optin_id || !empty(Optin_Monster_Output::get_instance()->data[$optin_id])) {
return false;
}
}
// Return the output.
return Optin_Monster_Output::get_instance()->get_optin_monster($optin_id);
}
示例7: install
/**
* Install WP Job Manager
*/
public static function install()
{
global $wpdb;
self::init_user_roles();
self::default_terms();
self::schedule_cron();
// Redirect to setup screen for new installs
if (!get_option('wp_job_manager_version')) {
set_transient('_job_manager_activation_redirect', 1, HOUR_IN_SECONDS);
}
// Update featured posts ordering
if (version_compare(get_option('wp_job_manager_version', JOB_MANAGER_VERSION), '1.22.0', '<')) {
$wpdb->query("UPDATE {$wpdb->posts} p SET p.menu_order = 0 WHERE p.post_type='job_listing';");
$wpdb->query("UPDATE {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id SET p.menu_order = -1 WHERE pm.meta_key = '_featured' AND pm.meta_value='1' AND p.post_type='job_listing';");
}
// Update legacy options
if (false === get_option('job_manager_submit_job_form_page_id', false) && get_option('job_manager_submit_page_slug')) {
$page_id = get_page_by_path(get_option('job_manager_submit_page_slug'))->ID;
update_option('job_manager_submit_job_form_page_id', $page_id);
}
if (false === get_option('job_manager_job_dashboard_page_id', false) && get_option('job_manager_job_dashboard_page_slug')) {
$page_id = get_page_by_path(get_option('job_manager_job_dashboard_page_slug'))->ID;
update_option('job_manager_job_dashboard_page_id', $page_id);
}
delete_transient('wp_job_manager_addons_html');
update_option('wp_job_manager_version', JOB_MANAGER_VERSION);
}
示例8: __construct
/**
* __construct function.
*/
public function __construct()
{
// Define constants
define('JOB_MANAGER_ALERTS_VERSION', '1.3.14');
define('JOB_MANAGER_ALERTS_PLUGIN_DIR', untrailingslashit(plugin_dir_path(__FILE__)));
define('JOB_MANAGER_ALERTS_PLUGIN_URL', untrailingslashit(plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__))));
// Includes
include 'includes/class-wp-job-manager-alerts-shortcodes.php';
include 'includes/class-wp-job-manager-alerts-post-types.php';
include 'includes/class-wp-job-manager-alerts-notifier.php';
// Init classes
$this->post_types = new WP_Job_Manager_Alerts_Post_Types();
// Add actions
add_action('init', array($this, 'init'), 12);
add_action('wp_enqueue_scripts', array($this, 'frontend_scripts'));
add_filter('job_manager_settings', array($this, 'settings'));
add_filter('job_manager_job_filters_showing_jobs_links', array($this, 'alert_link'), 10, 2);
add_action('single_job_listing_end', array($this, 'single_alert_link'));
// Update legacy options
if (false === get_option('job_manager_alerts_page_id', false) && get_option('job_manager_alerts_page_slug')) {
$page_id = get_page_by_path(get_option('job_manager_alerts_page_slug'))->ID;
update_option('job_manager_alerts_page_id', $page_id);
}
// Init updates
$this->init_updates(__FILE__);
}
示例9: embedPatreonContent
public function embedPatreonContent($args)
{
/* example shortcode [patreon_content slug="test-example"]
/* check if shortcode has slug parameter */
if (isset($args['slug'])) {
/* get patreon-content post with matching url slug */
$patreon_content = get_page_by_path($args['slug'], OBJECT, 'patreon-content');
if ($patreon_content == false) {
return 'Patreon content not found.';
}
$patreon_level = get_post_meta($patreon_content->ID, 'patreon-level', true);
if ($patreon_level == 0) {
return $patreon_content->post_content;
}
$user_patronage = Patreon_Wordpress::getUserPatronage();
if ($user_patronage != false) {
if (is_numeric($patreon_level) && $user_patronage >= $patreon_level * 100) {
return $patreon_content->post_content;
}
}
if (isset($args['youtube_id']) && isset($args['youtube_width']) && is_numeric($args['youtube_width']) && isset($args['youtube_height']) && is_numeric($args['youtube_height'])) {
return '<iframe width="' . $args['youtube_width'] . '" height="' . $args['youtube_height'] . '" src="https://www.youtube.com/embed/' . $args['youtube_id'] . '?rel=0&controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe>';
} else {
return self::displayPatreonCampaignBanner();
}
}
}
示例10: getArchive
function getArchive()
{
$page = get_page_by_path($_SERVER['REQUEST_URI']);
if (!is_null($page)) {
return !empty($title = trim(\get_post_meta($page->ID, 'quan_meta_title', true))) ? $title : '';
}
}
示例11: form
function form($instance)
{
$contact = get_page_by_path('contact');
$contact_info = get_post_meta($contact->ID, 'contact_info_widget', true);
if (empty($contact_info)) {
$contact_info['contact_info_title'] = __('Titel');
$contact_info['contact_info_body'] = '';
}
?>
<p>
<label for="contact_info_title">Titel</label>
<input id="contact_info_title" name="contact_info_title" value="<?php
echo $contact_info['contact_info_title'];
?>
" style="width:100%;" />
</p>
<p>
<label for="contact_info_body">Body</label>
<textarea id="contact_info_body" name="contact_info_body" style="width:100%;height:80px;"><?php
echo $contact_info['contact_info_body'];
?>
</textarea>
</p>
<?php
}
示例12: getArchive
function getArchive()
{
$page = get_page_by_path($_SERVER['REQUEST_URI']);
if (!is_null($page)) {
return !empty($description = trim(\get_post_meta($page->ID, 'quan_meta_description', true))) ? $description : false;
}
}
示例13: index
public function index($category_slug, $post_slug)
{
$post = get_page_by_path($post_slug, OBJECT, 'post');
$post = new TimberPost($post->ID);
$canonical_url = $post->catfish_importer_url;
return $this->client->getSubmissionStatus(get_field('instant_articles_status_id', $post));
}
示例14: old_wp_login_redirect
function old_wp_login_redirect()
{
if (!is_user_logged_in() && in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')) && get_page_by_path('login') != NULL) {
wp_redirect(get_site_url() . '/login/', $status);
die;
}
}
示例15: add_rewrite_rules
public static function add_rewrite_rules($rules)
{
//Get taxonomies
$taxonomies = get_taxonomies();
$blog_prefix = '';
$endpoint = Slash_Edit::get_instance()->get_endpoint();
if (is_multisite() && !is_subdomain_install() && is_main_site()) {
/* stolen from /wp-admin/options-permalink.php */
$blog_prefix = 'blog/';
}
$exclude = array('category', 'post_tag', 'nav_menu', 'link_category', 'post_format');
foreach ($taxonomies as $key => $taxonomy) {
if (in_array($key, $exclude)) {
continue;
}
$rules["{$blog_prefix}{$key}/([^/]+)/{$endpoint}(/(.*))?/?\$"] = 'index.php?' . $key . '=$matches[1]&' . $endpoint . '=$matches[3]';
}
//Add home_url/edit to rewrites
$add_frontpage_edit_rules = false;
if (!get_page_by_path($endpoint)) {
$add_frontpage_edit_rules = true;
} else {
$page = get_page_by_path($endpoint);
if (is_a($page, 'WP_Post') && $page->post_status != 'publish') {
$add_frontpage_edit_rules = true;
}
}
if ($add_frontpage_edit_rules) {
$edit_array_rule = array("{$endpoint}/?\$" => 'index.php?' . $endpoint . '=frontpage');
$rules = $edit_array_rule + $rules;
}
return $rules;
}