There are some "red flags" of sorts in your question:
"not working" — you are omitting essential parts of almost any question like what did you expect to happen and what actually happen. "not working" reads as "you figure it out for me".
Don't just drop generic statement like this, describe in detail what happens and what you have issue with.
give me step by step — this is falls on a wrong side of "teaching to fish / giving a fish". The purpose of this site is collecting knowledge, that you and others will benefit from.
If you focus on requesting your specific problem solved you are sending a message you are not here to learn, you just need someone to solve your problem [for free].
the code is below — is tricky one. Code is hard to read, always. For some questions it's essential. But it is hard to grasp what is the actual issue (if any) with your code. Does it break? Does it error? Does it do something different from what you expect?
If you include code in your question do a minimal amount of it and be very clear what in code is the issue.
As a result of above you actual question of where to put code was obscured by these.
How would I word such a question? My plan would probably be following:
- I am developing a theme and trying to achieve following functionality...
- My current attempt is following approach/code... [and I am facing following issues making it work: ...]
- I'd like to know [if approach makes sense and] how to properly integrate this in WordPress...