简体   繁体   English

如何让我的 WordPress slug 成为字符串数据?

[英]How can I make my WordPress slug a strings data?

I am currently gathering data from the SoundCloud API for my WordPress site, and I'm trying to set the permalink portion from the SoundCloud API as the slug in my WordPress site.我目前正在为我的 WordPress 站点从 SoundCloud API 收集数据,并且我正在尝试将 SoundCloud API 中的永久链接部分设置为我的 WordPress 站点中的 slug。


Here's some of my code which gathers the permalink ( not sure why you would need this but I am sure I'll get some heat if I don't have ANY code here .)这是我收集永久链接的一些代码(不知道你为什么需要这个,但我相信如果我这里没有任何代码,我会得到一些热量。)

$client_ID = 'xxxx'; 
$profilename = $_GET['pr'];

$sc = curl_init();
curl_setopt($sc, CURLOPT_URL, 'http://api.soundcloud.com/users/'.$user_ID.'/tracks?client_id='. $client_ID.'');
curl_setopt($sc, CURLOPT_HEADER, 0);
curl_setopt($sc, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($sc);
curl_close($sc);
$content = json_decode($output, true);
print $content[0]['permalink'];

/* not really important so commented out.

    print '<pre>';
    print_r($content);
    print '</pre>'; 

*/

The above code obviously returns all of the data for the tracks we have relating to the artist set within the pr variable.上面的代码显然返回了我们在pr变量中设置的与艺术家相关的曲目的所有数据。


If you look at the example above, I have printed out the permalink , in this case it reads as this stop-the-car-w-horsehead-prod-smokeasac .如果你看上面的例子,我已经打印出permalink ,在这种情况下它读作这个stop-the-car-w-horsehead-prod-smokeasac So I would like for my website's url to look like this.所以我希望我的网站的 url 看起来像这样。 http://www.example.com/track/stop-the-car-w-horsehead-prod-smokeasac instead of the default WordPress slug. http://www.example.com/track/stop-the-car-w-horsehead-prod-smokeasac而不是默认的WordPress slug。

I think you may have to override the default handler for the slugs.我认为您可能必须覆盖 slug 的默认处理程序。 If I understand you correctly, you want to have dynamic links to point to a specific page.如果我理解正确,您希望拥有指向特定页面的动态链接。 If you don't want to create each url in the database, you have to take a look at which file takes care of redirecting and maybe make a corehack to parse the result of your curl request to Soundcloud...如果您不想在数据库中创建每个 url,则必须查看哪个文件负责重定向,并且可能会使用 corehack 来解析您对 Soundcloud 的 curl 请求的结果...

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM