0

I am aware that it is possible to write a page template with custom PHP code to generate dynamic content.

For example, the page can take in a query parameter e.g. musician ID. It then uses custom PHP logic to retrieve the musician's info from database based on the ID, and generate the html for the musician's profile. Wordpress will treat this as one page, not the multiple pages that the user sees.

Example URLs for some musicians:

But these are in fact one single Wordpress page with additional PHP logic that I am going to write.

My question: Is it possible to add Wordpress comments (via comments_template()?) for each musician? That is, user will see a different set of comments for each musician.

1 Answer 1

1

You probably can hack comments in somehow, but don't. Create a custom post type for your musicians using register_post_type() and including "comments" support.

You can then create post type templates to customize the display:

  • archive-{post_type}.php -- for archives
  • single-{post_type}.php -- and for single posts

https://codex.wordpress.org/Post_Type_Templates

Comments should now work properly without your having to hack around with them.

2
  • Thanks for the answer. Does this mean I have to create one new page for each musician in Wordpress? I have amended the question to add: "the page can take in a query parameter e.g. musician ID. It then uses custom PHP logic to retrieve the musician's info from database based on the ID, and generate the html for the musician's profile. Wordpress will treat this as one page, not the multiple pages that the user sees."
    – adbie
    Commented Jan 6, 2016 at 4:39
  • Yes, you would, but you've already got the musician data the database. It would be trivial to use that data to create proper "posts" for them. Any other approach is going to be a lot of work, and you'd basically be recreating the comment subsystem. Comments are strongly tied to posts.
    – s_ha_dum
    Commented Jan 6, 2016 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.