0

I create some dynamic pages in Wordpress through PHP. Lots of them.

Those are not visible in Wordpress backend, as all the data is taken from different database. Each of them use signle PHP template, but have unique URL. Its working just fine.

I have also created taxonomy tags in Wordpress.

How to tell Wordpress that each of those dynamic pages with unique URLs should use specified tags?

Example: I have pets. Dogs and cats, each of them have their names.

I have tags in Wordpress: john, dog, joe, cat

I have page in Wordpress: mydomain.com/pets/

And I have dynamic pages created in PHP from external DB (as dynamic categories, not visible in Wordpress backend): mydomain.com/pets/cats/ mydomain.com/pets/dogs/

And dynamic subpages with names of pets created in PHP from external DB (also not in backend): mydomain.com/pets/cats/joe/ mydomain.com/pets/dogs/john/

How to tell Wordpress that page: mydomain.com/pets/cats/joe/ should be related to tags 'joe' and 'cat' and page: mydomain.com/pets/dogs/john/ should be related to tags 'john' and 'dog'

So if someone uses tag: mydomain.com/tag/john/ it will show him corresponding dog page........

Is it possible? I have plenty of names and a lot of pets ;)

edit: updated title

/orsz

0

Well, ideally you would want to have the data contained within the Wordpress database as you then have access to the framework for data manipulation and your data is stored in a relational way in terms of the normal Wordpress structure.

Custom post types for the pets and custom taxonomies for those post types would make sense. You could then create dynamic templates for each structure.

Why do you want to use Wordpress's tag structure for the pages if you do not use wordpress for the pages or info?

To take a stab at answering your question though, I would create custom taxonomy, lets say Animals, and make a WP page template within the theme for your post type and dynamic content:

category-animals.php 

and register your animals as children and their names as grandchildren.

Since you are not saving the data within Wordpress, you would have to provide some structure on the WP side for this to work, even if your data is generated from an external db.

The above will definitely let WP know:

How to tell Wordpress that page: mydomain.com/pets/cats/joe/ should be related to tags 'joe' and 'cat' and page: mydomain.com/pets/dogs/john/ should be related to tags 'john' and 'dog'

but Wordpress will still not have a clue about the data you present to the user.

I have not tested this as the use case is slightly strange but if your php code is with the custom category template, it should work

If you could explain what the reasoning is for keeping your data and structure outside of Wordpress that might help?

  • its a big external database with lots of relations. there is no space in Wordpress for this. I have only used Wordpress as a core because I could have an engine for users and user-management. I know that in perfect world all should be in Wordpress (or all custom) but I wanted to use Wordpress features on non-Wordpress content. I need to allow users to search for animals (and names) through Wordpress search engine. I thought tags are best way to do so... are they? – orsz Feb 9 '17 at 12:06
  • You won't be able to search through the actual content obviously, but using the taxonomy/tag structure I outlined above your tag structure should be recognized in wordpress and your custom code should already show the correct content if I am correct? If so, then that accomplishes what you are asking for. – Svartbaard Feb 9 '17 at 12:18
  • I think this may be what I am looking for "and register your animals as children and their names as grandchildren." Do you have any PHP example so I would know how to code it? – orsz Feb 9 '17 at 12:21
  • Simply register your custom taxonomy in functions.php, <?php register_taxonomy( $taxonomy, $object_type, $args ); ?> And add your tags in a tested structure to this taxonomy, the url mydomain.com/pets/dogs/ should correspond of you place your custom php code in a taxonomy template and do with the data as you wish. – Svartbaard Feb 9 '17 at 12:33
  • I would like to use the tags I have been already using in Wordpress pages. As far as I understand taxonomies, the taxonomy is already created. But I want to start using it on my PHP dynamic pages.... – orsz Feb 9 '17 at 12:38
0

I feel like you are using wordpress, without the need for it.

You can create a simple php page or include that page in your default wordpress page in wich you get the tags from the url and include the needed .php file(s) in the original template page?

Using parse_url & explode you can get the tags from your url

$uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri_segments = explode('/', $uri_path);

You can then loop these segments to incldue what you want

include $uri_segments[1].'.php';
include $uri_segments[2].'.php';

Your question is a bit unclear to understand if this is really what you are looking for.

  • thanks for your answer, but this is not what I need. I know I can parse end explode. I need Wordpress search engine to allow users searching in my custom php pages that are not in Wordpress. By tags. – orsz Feb 9 '17 at 12:10
  • I'm afraid that won't be possible then, the search will not work on external data, since it has no access to it... which seems quite obvious? – woony Feb 9 '17 at 12:13
  • could be....... but I have all the tags created in Wordpress and all the tags in my external DB. Is there a way to match them? On page: /pets/dog/john/ I use 'dog' and 'john' which somehow should be linked to Wordpress tag 'dog' and 'john'? :-) So Wordpress would know if someone is asking for john, the answer is /pets/dog/john/ – orsz Feb 9 '17 at 12:16
  • Ok, you do not want to search the content of the pages but just the tags? You could create a page that loops through all your tags and generates url's to those pages creating an index or menu structure? – woony Feb 9 '17 at 12:18
  • This could be the answer. Could you please let me know how to do that? – orsz Feb 9 '17 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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