Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何添加页面';s slug到wordpress小部件中的链接_Php_Wordpress_Url_Widget_Slug - Fatal编程技术网

Php 如何添加页面';s slug到wordpress小部件中的链接

Php 如何添加页面';s slug到wordpress小部件中的链接,php,wordpress,url,widget,slug,Php,Wordpress,Url,Widget,Slug,我已经找了一个多小时了,所以我真的希望有人能帮我 我有一个小部件,其中包括一个链接,例如 <a href="/form/fill-in-form">Fill in our form</a> 但是我想将页面slug添加到链接中(这样我就可以在表单上看到它)。例如,如果用户在我的页面mysite.com/listing/redcar上,我希望他们看到: e、 g 或 但无论我做什么,我都无法让slug进入小部件中的URL 我试过了 <a href="/fo

我已经找了一个多小时了,所以我真的希望有人能帮我

我有一个小部件,其中包括一个链接,例如

<a href="/form/fill-in-form">Fill in our form</a>

但是我想将页面slug添加到链接中(这样我就可以在表单上看到它)。例如,如果用户在我的页面mysite.com/listing/redcar上,我希望他们看到: e、 g



但无论我做什么,我都无法让slug进入小部件中的URL

我试过了

<a href="/form/fill-in-form/?myparameter=<?php the_permalink(); ?>">Fill in our form</a> 

还有很多其他的事情,但我就是什么都做不了


有什么想法吗?

使用global获取post slug

<?php 
    global $post;
    $post_slug = $post->post_name;
?>
<a href="/form/fill-in-form/?myparameter=<?php echo $post_slug; ?>">Fill in our form</a> 

你也可以通过post id获得slug,这样做

<?php
$post_id = POST_ID; //replace it with post id
$post_data = get_post($post_id); 
$post_slug = $post_data->post_name;
?> 
<a href="/form/fill-in-form/?myparameter=<?php echo $post_slug; ?>">Fill in our form</a> 


谢谢Regolith-我试过了,但后来链接添加了%3C?php%20echo%20$post_slug;%20?%3E.g.它变成了:我在一个widgetAll中使用它很好!我把php放进了我的函数中,但它放进了小部件本身:)非常感谢Regolith
<?php 
    global $post;
    $post_slug = $post->post_name;
?>
<a href="/form/fill-in-form/?myparameter=<?php echo $post_slug; ?>">Fill in our form</a> 
<?php
$post_id = POST_ID; //replace it with post id
$post_data = get_post($post_id); 
$post_slug = $post_data->post_name;
?> 
<a href="/form/fill-in-form/?myparameter=<?php echo $post_slug; ?>">Fill in our form</a>