in a php script which is basically unaware of the page it's inserted in, how could I get the post ID if I'm using permalinks, so - url_to_postid( $url ); is out of the question, also, using global $post; won't help either.
The only place in my html where the id is shown is in the body tag as class"... postid-7777 .."
If I'm inserting specific ID directly it works, but I need it to look for the ID automatically so that "related posts" could be shown...
I'm not a php programmer (yet) so I'd really appreciate your help
Use the wordpress global $post (as long as you are inside the loop) to get the id and other information about the current post.
More information here:
You can try get_queried_object(). There is also get_queried_object_id(), both worked several times for me.