0

I've built a small website that fetches multiple rows from a database, organizes them on a page, and provides the ability to change their content via ajax requests. The website was missing the registration part, so I decided to create a WP plugin instead and use its powers to handle user privileges. The plugin is installed with the register_activation_hook:

register_activation_hook( __FILE__, array( 'Lyriqa', 'install' ) );

that creates several SQL tables. This where I got stuck actually, because I am not sure how to embed my custom code inside the theme body. So basically, I need to have WP header, footer, sidebar, etc., but have my custom content instead of the posts. Is it something a plugin can handle, or is it something that a theme should handle? Any advice would be appreciated.

1 Answer 1

2

No need for a plugin:

There are 2 ways you could do this.

The first would be by creating a separate template for each of the pages you want. This is if you're going to change a lot of different aspects of the page for each page.

A page template will include the header, footer, and sidebar calls for you. You'll be able to insert the php in the main body container that is created by the template.

The best way to start creating a page template is by copying one from your current theme. Likely your theme is already using one and all you have to do is pull one from the main theme directory and copy it to your child theme directory. Then look for the main container and put your php coding there.

Make sure to change the template name to your own in the top of this file. Now, when you create a new page in your wp dashboard, simply choose the template from the template drop down on the left, hit publish, and your content will be there.

The 2nd way would be to add add your content as functions to be called later. (either in your functions.php or an included php file you create) and call the functions in your page. If you do this, it provides the option of creating a shortcode that you can call on any page, or directly call the function dynamically through conditional calls on a template page.

1
  • Thanks for a thorough explanation. I came from a different CMS, which had it all a bit different. However, the whole process makes sense to me now! Thanks again!
    – Deka87
    Commented Apr 17, 2017 at 20:04

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.