Forums

Adding PHP code to a page (8 posts)

  1. josephmo
    Member
    Posted 4 months ago #

    I have some PHP code that interfaces with a database, retrieves information (picture, names, etc), for a number of people. In a standalone web page, the code generates the HTML code to make this happen. What do I need to do to get this code to run and display inside one of the pages on my WordPress installation.

    Regards,

  2. MichaelH
    moderator
    Posted 4 months ago #

    Couldn't you just put the code in a Page Template?

  3. josephmo
    Member
    Posted 4 months ago #

    Thanks for the tip. I'm going to try it.

  4. awarner20
    Member
    Posted 3 months ago #

    @ MichaelH,

    I have the same question, but can't use a page template. The reason is that I need to be able to use the visual editor on this page still (someone will be changing the content regularly on this page), but I have a custom query that I would like to run on this page.

    Is it at all possible to run PHP in regular WordPress pages?

  5. phpprincess
    Member
    Posted 3 months ago #

    @awarner20, yes it is. You would need to edit the default Page Template -- it's usually named page.php in your theme set.

  6. awarner20
    Member
    Posted 3 months ago #

    Hey there phpprincess, nice to see you here...

    Unfortunately, I don't think your method will work as this custom query would be different on many pages (at least 30). Unless I had one really long if statement perhaps?

    I did try the exec-php plugin, but in order to use that I would need to disable the Visual Editor, which would negate my purpose in trying retain the editing page feature for the user that will be editing these pages.

    For now, I am just using separate page templates, each with custom queries, and each with static HTML. If this needs to be changed by the user, I'll just have to make those changes for now.

    p.s. These are category page templates.

  7. ssgupta
    Member
    Posted 3 months ago #

  8. awarner20
    Member
    Posted 3 months ago #

    @ ssgupta,

    Thanks, but as noted in my previous post above, exec-php will not work for my needs.

Reply

You must log in to post.

About this Topic

Tags