cihan Posted October 2, 2009 Share Posted October 2, 2009 Hi, i'm a wordpress user and i have a php code, and in that php code there is an area to put a url in: $url = "http://blabla.com"; Well, in wordpress you can display post permalinks with this code: <?php the_permalink(); ?> What i want to do is putting <?php the_permalink(); ?> instead of http://blabla.com above in the php code. Target is: Getting permalinks and putting them there in php code, and let the php code use them to do its job. Is that possible? If yes, how with an example please...Thank you... Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 2, 2009 Share Posted October 2, 2009 Hi cihan, Just do: $url = the_permalink(); Hope this helps. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted October 2, 2009 Share Posted October 2, 2009 Depends on what the_permalink() returns. From the OP's example it seems it outputs the link. Quote Link to comment Share on other sites More sharing options...
cihan Posted October 2, 2009 Author Share Posted October 2, 2009 Do you mean: $url = "the_permalink();"; or $url = the_permalink(); I tried both of them but not working... Warning: file_get_contents(the_permalink() [function.file-get-contents]: failed to open stream: No such file or directory Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 2, 2009 Share Posted October 2, 2009 What are you doing with the $url variable? I assume using file_get_contents() on it? Try using the get_the_permalink(); variable instead, or possibly get_permalink($post->ID); (not too sure with Wordpress) Hope this helps. Quote Link to comment Share on other sites More sharing options...
cihan Posted October 2, 2009 Author Share Posted October 2, 2009 i'm trying to put the permalink into this php code: <?php $url = "http://blabla.com"; $allowedDomains = array ( 'rapidshare', 'megaupload', 'depositfiles', 'letitbit', 'hotfile', 'sherebee', 'filefactory', 'zshare', 'sendspace', 'uploadbox', 'uploading', '4shared', 'gigasize', 'mediafire', 'netload', 'linksave', 'filehoster', 'rghost', 'protector' ); $page = file_get_contents($url); preg_match_all("/<a.*?href=(\"|\')(.*?)\\1.*?>.*?<\/a>/is", $page, $matches); echo "<pre>"; //print_r($matches); echo "<pre>"; echo "Download Links:"; echo "<ul> "; foreach ($matches[2] as $match) { $validDomain = false; foreach ($allowedDomains as $domain) { if (strpos($match, $domain)) { $validDomain = true; break; } } if ($validDomain) { echo "<li><a href=\"{$match}\">{$match}</a></li>"; } } echo "</ul> "; ?> and get_the_permalink(); is not working, either... Quote Link to comment Share on other sites More sharing options...
Bricktop Posted October 2, 2009 Share Posted October 2, 2009 OK, the Wordpress functions aren't working because you're not declaring them in the PHP code. Like I said not sure how Wordpress works but somewhere it will declare functions, i.e. with an include or similar. You need to make sure this is included in your code above so the Wordpress functions will run. Hope this helps. EDIT: Just downloaded Wordpress and these are hopefully the lines you need to include: define( 'ABSPATH', dirname(__FILE__) . '/' ); require_once( ABSPATH . '/wp-includes/classes.php' ); require_once( ABSPATH . '/wp-includes/functions.php' ); require_once( ABSPATH . '/wp-includes/plugin.php' ); Quote Link to comment Share on other sites More sharing options...
cihan Posted October 3, 2009 Author Share Posted October 3, 2009 I thing it was a bad idea what i want to do, just forget about it and thanks for helping me to Bricktop and thebadbad. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.