有人知道我如何获得当前页面的帖子ID吗?
因此,如果我在header.php中的某个特定帖子上,我希望能够获得当前的帖子id。
谢谢
有人知道我如何获得当前页面的帖子ID吗?
因此,如果我在header.php中的某个特定帖子上,我希望能够获得当前的帖子id。
谢谢
尝试使用此:
$id = get_the_ID();
您可以使用$post->;ID
以获取当前ID。
在大多数情况下,get_the_ID()
将正常工作:
$post_id = get_the_ID();
但是,在某些情况下,您可能需要使用get_queried_object_id()
改为:
$post_id = get_queried_object_id();
原因是get_The_ID()
返回的值依赖于上下文,在某些情况下,可能会返回与所查询的主帖子不同的ID。有关更多信息,我建议阅读WordPress关于循环。
global $post;
echo $post->ID;
尝试:
$post = $wp_query->post;
然后传递函数:
$post->ID
您可以通过以下代码获取id。。。它简单快捷
<?php $post_id = get_the_ID();
echo $post_id;
?>
I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...
<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...
I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image. And is there a better way to create ...
如何确认来自正确来源的数字。
Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...
I wonder there is a way to post a message to a facebook business page with cURL? thanks
I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...
How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...