Iftikhar uddin Iftikhar uddin - 2 years ago 97
PHP Question

How to get ID from URL in WordPress

I have programming experience from PHP but now I am creating a WordPress theme which is a bit mixture.I have a blog which contains posts , when a user click on a post i want to show the clicked

content in the other page , i am new to wordpress i want to show the details of my each post in the details page.How can i do that ?

Homepage: Contains a loop for displaying all posts

Now i want a page which display each post separately when a user click any post from homepage.

Lee Lee
Answer Source

May be steps below should do it

  1. Make receive.php as template, add <?php /* Template Name: theTemplateName */ ?> at the beginning of template file.

  2. Create a page, give it a slug, let say the-receiver, make sure you select theTemplateName as its template.

  3. Now, create a form inside single.php, give an (hidden) input with value from get_the_ID(), set it POST/GET whatever suits you, and the action to site_url('/the-receiver'), match the url to the slug the page that is using your receiver template name. Watch now button should submit the form.

  4. Inside the file/template receiver.php, do your stuff.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download