-1

I'm putting together a WordPress site for a charity organization which upgrades the look & feel of their existing site. Their existing site had a few PHP scripts and an events database for their project listings and I changed the output so that the script emulates the WordPress UI using:

    define( 'WP_USE_THEMES', true );
    require_once "wp-load.php";

The site uses the Monarch social plugin to enable sharing and I need to have that work on the emulated project page.

I haven't been able to find what I should include.

I tried adding both of these lines, separately, but they had no affect:

    require_once "wp-content/plugins/monarch/monarch.php";
    require_once "wp-content/plugins/monarch/core/init.php";

Upon looking at the code and trying to call functions that looked like potential functions to execute it, they resulted in an error or does nothing.

Phil
  • 320
  • 4
  • 16
  • The easiest way to do this is to probably just use a WordPress page template. You can then call `get_header()` and `get_footer()` which will give you all the WordPress-goodness, but then in the middle you can do whatever you want in PHP – Chris Haas Oct 12 '22 at 17:02
  • I'm already doing that. get_header() gives me the header that I use on the rest of the site. What I don't know is the plugin function that will get the social plugin stuff to display. – Phil Oct 12 '22 at 17:28
  • You probably want to use a shortcode then: https://www.elegantthemes.com/documentation/monarch/shortcode/ – Chris Haas Oct 12 '22 at 17:33
  • Like I said, I'm using a stand-alone PHP script that's reading from a non-WordPress database to display data that I only want to look like it is part of a WordPress site. The output already looks like a WordPress page on that site BUT it does not have the Monarch social plugin. There's very likely a function that needs to be called to instantiate it but I haven't looked through all of the plugin code to correctly determine which function it would be. – Phil Oct 12 '22 at 22:13
  • It might be more than just a simple function, we don't know how that plugin actually works. It might for example get the URLs that are supposed to be shared based on nothing but a post ID, and then uses other WP functionality to look up / create the URL based on that. But that won't work, if you are in an environment where you don't actually have any "posts" to begin ... – CBroe Oct 13 '22 at 09:03
  • You are contradicting yourself, although maybe it comes down to nomenclature. I said using a template is probably the easiest way, and you said you are doing that, then you say you are using a stand-alone PHP script. Which is it? If it is a native WordPress template, you are a 100% first-class citizen in the WordPress world and shortcodes are available to you. To be clear, I'm talking about a [page template](https://developer.wordpress.org/themes/template-files-section/page-template-files/) – Chris Haas Oct 13 '22 at 13:17
  • Sorry. Yes nomenclature issue then b/c I'm not a big WordPress person. It is a stand-alone PHP script that is generating output and trying to emulate the UI/look & feel of the rest of the WordPress site. You can see the script in action at https://www.pmd.org/staging/project.php. Every page at https://www.pmd.org/staging/ properly shows the Monarch plugin and I just want to know what function to call to instantiate it within the project.php script. – Phil Oct 13 '22 at 15:19
  • You can also see on the home page https://www.pmd.org/staging that there is a project listing starting at the top after the first image. That is generated using PHP via the Code Snippets plugin added to the page by using a shortcode. The View More Info button makes reference to the project.php script with an id for the specific project. If there is a different way to have a script where WordPress can manage the "pages" but I don't have to create a page for each individual ID I'm happy to go about this in a different manner... – Phil Oct 13 '22 at 15:22
  • 1
    Try making a WordPress template using the link I posted, it is basically just putting a special PHP comment on the top of the page and then content authors will see it in their templates. In your templates call for the header and footer, and between those two things do your custom PHP stuff. Tell your content authors that except for the page title, anything else that they put on that page will be completely ignored, it is only a way to get your PHP into WordPress. If this works for you there's some further advanced things you could do, but try this first. – Chris Haas Oct 13 '22 at 15:39
  • @ChrisHaas Thank you. This worked. I didn't realize page templates could be leveraged in this way because I was hung up on the page/post as the "source" for the content. – Phil Oct 14 '22 at 20:38

1 Answers1

0

As someone completely unfamiliar with the intricacies of WordPress doing a pro bono favor for a charity organization, I did not realize that page templates could be used as the destination for custom PHP code accessing a non-WordPress database, etc.

The solution steps (which may hopefully help someone else equally unaware of WordPress) are as follows:

  • Use the page template page as reference to create a page template.
  • I added my page template to the same location as the theme's page.php template
  • Then create a page in WordPress and specify its template as the one just created.
  • Call that new page with whatever parameters after ?xyz=value;abc=etc. as needed

This may be basic for people who live in WordPress but it wasn't immediately clear to me.

Thanks to the comments by @ChrisHaas!

Phil
  • 320
  • 4
  • 16