How to add dynamicly linked and created pages in wordpress?

Since I had some comments on the formulation of my question, I decided to rewrite it completely. And also, I understand a little bit more about wordpress so it should make more sense now.

So, let’s start with what I’m trying to accomplish by using a simple example:

Read More

Goal:

Make a search engine for some products and link to them using a database to generate the information.

Result:

http://my.site.url/wordpress/<plugin-name>  <-- The page with the "search" and "search result
http://my.site.url/wordpress/<plugin-name>/products/<product_name>  <-- When click on a search result

Part 1:

I want to make a plugin with the name “plugin-name” Right now, I put my code in

http://my.site.url/wordpress/wp-content/plugins/<plugin-name>

On the activate, I create some tables with some data. Since there is no page yet, I create 1 on the fly using the API call ‘wp_insert_post’. I give the name and slug “myPlugin”.

So, when I go on the main site, I can see my newly created page “myPlugin”. But right now, there is no content attached to it. To do so, from what I understand, I need to create a page in my plug-in directory named “myPlugin.php”.

http://my.site.url/wordpress/wp-content/plugins/<plugin-name>/myPlugin.php

So, how do I link the page I created manually and the source file in the plugin directory?


Part 2

When clicking on a link in the search result, I would like to have a page “product.php” and display its information. So, is it possible to create a “temporary url” for the result using sub pages (see result at the beginning)? And if possible, how can we achieve that?


Thanks in advance and I hope it’s clearer.

Related posts

Leave a Reply

3 comments

  1. thisMayhem is right. This sounds like a bunch of nonsense. But, if you’re trying to make a WP page that executes some custom PHP, look up the WP template hierarchy.

    What you can do is this:

    • create a WP “page” – call it “Search results.”
    • create a template directory file called page-search-results.php (filename corresponds with slug of page from step 1)
    • put some generic header/footer stuff there (see other template files – most often it’s just a question of putting in <?php get_header(); ?> and <?php get_footer(); ?>)
    • put PHP code in that thar page. in them hills.
    • if you use a caching plugin, may want to put an exemption for /search-results/

    So, when someone pulls up http://your.site/search-results/ – your custom PHP code will execute. It’s up to you to make that logic and communication happen – whether via $_GET or $_POST, etc.

  2. I’m sorry you’re experiencing some problems. Unfortunately as we say above because it’s a ‘one off’ for a client project we can’t support it – it works for them 🙂 Feel free to rip it apart and retest and if you have any success let us know.