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. коли це можливо.


27 Responses to “Retrieve and Get WordPress Post ID Outside the Loop as PHP Variable” 27 Відповіді на "статтю і отримати WordPress Поштові ID поза циклу, як PHP Variable"

Pages: [2] Сторінки: [2] 1 1 » » Show All Показати все

  1. Konisto Konisto
    November 7th, 2009 03:41 7 листопада 2009 03:41
    27 27

    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 Спасибо

  2. Blake Блейк
    October 30th, 2009 02:22 30 жовтня 2009 02:22
    26 26

    Thanks, this was super-helpful and easy to understand! Дякую, це було супер-корисні й легкі для розуміння! I love code samples! Я люблю зразки коду!

Pages: [2] Сторінки: [2] 1 1 » » Show All Показати все

Leave a Reply Написати відповідь

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> Ви можете використовувати ці теги: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <справі DateTime = ""> <em> <i> <q Cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. Підписатися на коментарі функція була відключена. To receive notification of latest comments posted, subscribe to Щоб отримувати повідомлення про останні коментарях, підписатися My Digital Life Comments RSS feed Моя Цифрова життя Коментарі RSS Feed or або register to receive Увійдіть, щоб отримувати new comments in daily email digest. нові коментарі в щоденній електронній пошті.
Custom Search

New Articles Нові статті

Incoming Search Terms for the Article Вхідні терміни пошуку для статті

wordpress get post id WordPress отримати посаду ID - -- wordpress post id WordPress Post ID - -- wordpress get page id WordPress отримати ідентифікатор сторінки - -- $post->ID $ POST-> ID - -- post id wordpress Поштові ID WordPress - -- get post id wordpress отримати пост ID WordPress - -- get post id отримати пост ID - -- wordpress get current page id WordPress отримати поточний ідентифікатор сторінки - -- wordpress get current post id WordPress отримати нинішню посаду ID - -- wordpress $post->ID WordPress $ POST-> ID - -- wordpress get id отримати ID WordPress - -- wordpress current page id WordPress поточний ідентифікатор сторінки - -- wordpress current post id WordPress нинішню посаду ID - -- $post->ID 104 wordpress $ POST-> ID 104 WordPress - -- wordpress get id of current page WordPress отримати ID поточної сторінки - -- get current post id wordpress отримати поточну посаду ID WordPress - -- $post->id wordpress $ POST-> ID WordPress - -- get post id outside loop отримати пост ID зовнішня петля - -- wordpress current post WordPress нинішній пост - -- post id Поштові ID - -- wordpress get current page WordPress отримати поточну сторінку - -- wordpress post id outside loop WordPress Post ID зовнішня петля - -- wordpress get id post WordPress отримати ID пост - -- wordpress postid WordPress PostID - -- get page id wordpress отримати код сторінки WordPress - -- wordpress id post WordPress Post ID - -- wordpress id WordPress ID - -- wordpress get current post WordPress отримати нинішню посаду - -- wordpress get the post ID WordPress отримати посаду ID - -- wordpress get post id outside loop WordPress отримати посаду ID зовнішня петля - -- wordpress page id variable WordPress ідентифікатор сторінки мінлива - -- post->ID Post-> ID - -- post- id wordpress Post-ID WordPress - -- wordpress php post ID WordPress посаду PHP ID - -- wordpress global post WordPress глобальної пост - -- how to get page id in wordpress Як отримати ідентифікатор сторінки в WordPress - -- wordpress latest post id WordPress останнє повідомлення ID - -- wordpress get post by id WordPress отримати посаду за ідентифікатором - -- get post category wordpress WordPress отримати посади категорії - -- get current page id wordpress отримати поточну сторінку ID WordPress - -- wordpress post date outside loop WordPress Дата пост зовнішня петля - -- wordpress find post id WordPress знайти пост ID - -- how to get id php wordpress Як отримати ID WordPress PHP - -- how to get a post id in wordpress in page.php Як отримати ID пост в WordPress в page.php - -- wordpress get page by id WordPress отримати сторінку по ID - -- get wordpress post ID отримати WordPress Post ID - -- get id wordpress отримати ID WordPress - -- post_id wordpress post_id WordPress - -- post id outside loop Поштові ID зовнішня петля - -- post info outside loop Post Info зовнішня петля - --