Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable Отримати статтю і WordPress Поштові ID поза циклу, як РНР змінні
In WordPress, each post has unique anchor identifier in the form of numeric post ID. У WordPress, кожна посада має унікальний ідентифікатор, якір у вигляді числового ідентифікатора повідомлення. When inside the Loop, where WordPress processes and displays each of the posts to be displayed on the current page and formats them according to how they match specified criteria within The Loop tags, template tag the_ID can be used to easily display the post's ID inside the post. Коли всередині циклу, де WordPress процеси і виводить кожну з посад, які будуть відображатися на поточній сторінці і формати їх у відповідності з якою вони відповідають зазначеним критеріям у циклі тегів, тег шаблону the_ID може бути легко використаний для відображення ID поста всередині пост. Alternatively, inside the the_content filter, declare $id global and use $id to retrieve the post ID. Крім того, всередині the_content фільтр, оголосити $ Id глобальних і використовувати $ ID для отримання ідентифікатора повідомлення.
the_ID template tag can be used in the following format: the_ID шаблон тег може бути використаний у наступному форматі:
<?php the_ID(); ?> <? PHP the_ID ();?>
Outside the Loop or out of the context of the post, such as in header of footer and even sidebar area in the templates of WordPress's blog, the_ID() cannot be used as a function. Поза циклу або з контексту цієї посади, такі як заголовки колонтитулі і навіть бічній області в шаблоні блогу WordPress's, the_ID () не може бути використана як функції. Instead, $post->ID will be used to return the post ID (the syntax can also be used inside the Loop of the post by declaring $post as global). Замість $ POST-> ID буде використана для отримання ідентифікатора повідомлення (синтаксис може бути використаний всередині циклу пост, заявивши, $ POST, як глобальні). $post is a global object that holds various information about the posts displayed on the page. $ Пост є глобальний об'єкт, який містить різноманітну інформацію з приводу повідомлень, що відображаються на сторінці. So $post->ID will return the post ID of the post. Таким $ POST-> ID повернеться пост ідентифікатор повідомлення. It the $post is used inside a function, the $post has to be declared as a global variable. Це $ POST використовується всередині функції, $ посаду повинна бути оголошена як глобальна змінна. For example: Наприклад:
// Works inside of the Loop
function function_name() {
global $post;
$thePostID = $post->ID;
}
or: або:
// Works in single post outside of the Loop
function function_name() {
global $wp_query;
$thePostID = $wp_query->post->ID;
}
$post->ID can be called directly outside of the Loop too in a single post template, such as <?php echo $post->ID ?> will print display the post's ID number. $ POST-> ID може бути здійснений безпосередньо за межі циклу теж в один шаблон повідомлення, таких як <? PHP Відлуння $ POST-> ID?> Виведе відображення ідентифікатора записів.
In the multiple posts view page such as index page or archive page, it's possible to retrieve the get the latest or earliest post ID of all the posts displayed on the page by using an ORDER BY clause to order the posts by date, and then set the number of record to LIMIT 1. У декількох посад перегляду сторінки, такі як сторінка індексу або сторінка архіву, це можливо, щоб отримати отримати останню чи ранній пост ідентифікатора всіх повідомлень, що відображаються на сторінці з допомогою ОКВЕК ПЗ на замовлення повідомлень за датою, а потім встановіть Кількість записів LIMIT 1.
Just for example, and there are various way to use the query: Просто для прикладу, і існують різні способи використання запиту:
//Get the latest post ID number / / Отримати останню посаду Номер
$post->ID ORDER BY post_date ASC LIMIT 1 $ POST-> ID ORDER BY post_date ASC LIMIT 1
//Get the earliest post ID number / / Отримання першу посаду Номер
$post->ID ORDER BY post_date DESC LIMIT 1 $ POST-> ID ORDER BY post_date DESC LIMIT 1
IMPORTANT : The page is machine translated and provided "as is" without warranty. ВАЖЛИВО: Сторінка машина переведена і надаються "як є" без гарантії. Machine translation may be difficult to understand. Машинний переклад може бути важким для розуміння. Please refer to Будь ласка, зверніться до original English article оригінальний англійська статтю whenever possible. коли це можливо.
Related Articles Статті за Темі
- Paginating or Split WordPress Post or Page with NextPage in WordPress Not Working Посторінковий або Спліт WordPress Розміщувати або сторінка з СледующаяСтраніца У WordPress не працює
- Disable and Turn Off Post Revisions Tracking in WordPress 2.6 or Above Вимкнути і відключити відстеження зміни стовпа в WordPress 2.6 або вище
- How to Delete Existing WordPress Post Revisions Stored/Saved Як видалити існуючі WordPress зміни стовпа зберігаються збережені /
- How To Store Every Post Revisions on Each Auto-Save in WordPress with Limit on Versions Count Як правильно зберігати кожне повідомлення ревізії на кожному автозбереження в WordPress з лімітом за версією графа
- Adding Extra More Fields to WordPress Write/Edit Post/Page Right Column Додавання додаткового кілька полів для WordPress Створити / Редагувати Post / Page правій колонці
- How to Change the Frequency or Interval WordPress Auto Saves An Editing Post or Page Як змінити частоту або інтервал WordPress Auto Зберігає Редагування Поштові або сторінку
- How to Wrap AdSense Ads Around and Inline Beside Blogger Post Content Як Wrap AdSense оголошення навколо та вбудовані поруч Blogger опублікувати яку
- Move Blogger Inline Ads Between Posts to Inside Within Post Position Move Blogger вхідні об'яви між посадами в рамках Всередині Поштові Позиція
- Place AdSense Ad Unit In Various Positions Inside Within Blogger Post Contents Місце рекламний блок AdSense в різних позиціях всередині рамках Blogger Поштові Зміст
- How to Display Elements (Ads) Only On (Or Only Not At) Individual Single Post Item View Як відображати елементи (оголошень) Only On (Або тільки не в) Індивідуальна Single Post Пункт Відкрити










































November 7th, 2009 03:41 7 листопада 2009 03:41
Hi, Привіт,
I'm trying to modify a custom post-new.php in the admin area and need to access the post_id of a post that I'm currently editing and that has not yet been published. Я намагаюся змінити користувальницький після new.php в адмінку і потребують доступу post_id посади, що я в даний час монтажу і, що ще не був опублікований. Any idea how I could do that? Будь-яка ідея, як я можу це зробити?
Thanks Спасибо
October 30th, 2009 02:22 30 жовтня 2009 02:22
Thanks, this was super-helpful and easy to understand! Дякую, це було супер-корисні й легкі для розуміння! I love code samples! Я люблю зразки коду!