Migrating custom database pages to Wordpress - php

I've been toying with the idea of using Wordpress as a CMS to replace the various database-driven pages I've kludged together over the years. I'm wondering though if there's a seamless way to grab info from a database based on the URL.
e.g. I have pages that serve up info on awards
/academy-awards grabs the intro info from the database
/academy-awards/32 grabs the intro info about the 32nd edition
/academy-awards/32/winners grabs the results and commentary for that ceremony
Now, academy-awards is actually an extensionless php file and depending on what comes after it (nothing, a number, a number and word) it serves up the various pages.
How would/could I translate that work into Wordpress? I'm a complete WP noob, so I'm hoping your initial answers can help me dig a little more.

Unless there is already an import filter or plugin, there's no easy way to import post/page data into Wordpress posts/pages without making and using a custom database query that will insert what you want into the correct spots in the WP database schema.
That said, you can export tables out of phpmyadmin into CSV or plain text and then manipulate that data into a a file that when imported will generate WordPress posts/pages. See http://codex.wordpress.org/Database_Description
Also think about setting set up a demo WordPress site, enter some posts/pages and then Export from Dashboard>>Tools>Export and see how a WordPress WXR file is constructed. That is a good format to arrange your data for import. See http://codex.wordpress.org/Tools_Export_Screen
If you simply want to display data from another database, use the wpdb Class. See https://codex.wordpress.org/Class_Reference/wpdb

After digging around some more it appears I can access info from other databases by using Custom Queries (http://codex.wordpress.org/Custom_Queries) and combining them with page templates.

Related

Change Post Id in wordpress post

I have to add the custom Post id for the custom post type. can anyone help me?
Check screen short for more details. http://prntscr.com/mo3eyu
This is a work around that works.
Background info:
We maintain a few almost identical web pages with different branding. The code repo is shared across these. The developers hard coded page IDs into the PHP in the past. I was asked to add new pages. After adding new pages on each website, I noticed the IDs were all randomly generated. This was breaking PHP code's logic. So, I needed to edit these IDs just like OP.
The work around:
In WP web admin page, there's an export / import functionality under tools menu. The new pages should be created in one site, then exported / imported onto other websites. This way, page IDs don't get created randomly. It copies the IDs from the exported page. So you can have same IDs on all pages.
PS:
Not sure why the past developers decided to hard-code page IDs in the code. This shouldn't have been the case to start with. When you don't have much time to refactor everything, stack overflow always comes to help.
IDs determine post record storage in database, changing them directly would be highly prone to breaking things. For example extensions often store IDs as a way to refer to specific post and do something with it.
The simple way to change to some ID would be to just create a new post and copy data over (through admin or with code either).
Post ID of a post also reflect in tables other than Post table, like post comments table. Changing post ID will disturb the relationship of post table with other tables, so it is not advisable.

Wordpress admin plugin to save hidden input data to database

I am creating a Wordpress plugin for the admin area. It needs to set options and write to a file and database based on the options that are saved.
I have tried creating a "Create File" button which sends POST data back to itself. I now need to create a file and add a column to the database based on a hidden boolean filed.
I'm struggling because I can't do what I want because the form needs to have a different action. Any advice on how to so this?
What a different action? Without any code examples that show what you're doing and what exactly is not working, we only can imagine and give you general info. In Wordpress, you don't have to care about naked url options cause the core will do this for you. Its enough to register the required hooks, read the passed data here and do what is required with them. Simple storing settings wouldn't require to extend the database scheme, since Wordpress already have a table for this. You could use the Wordpress functions here.
See the article of the Wordpress developers page: https://codex.wordpress.org/Creating_Options_Pages
Using the hooks, its no big deal to create a file too. Simple write your PHP code after saving the settings in the database. How you concretely do this depends on the requirements: Is the data passed as form field? Is it fetched from an external source (like api)? Depending on the requirements this should be done with relatively less work using a search engine, cause enough sample codes exists for those scenarios.

PHP Widget layout grid

I'm building a webapp which main purpose is displaying widgets on a display. These widgets have an variable size, so not every widget is even high or wide (But they are using standards like for example a grid system). Now I'm looking for the best way to save which widgets are used, and where they are placed. For example by using something like Gridstack the user can drag and place the widgets in an admin panel, but how should I save this? And how can I recall this and put in a empty Bootstrap page for example. Working with the Bootstrap Grid system would be great aswell.
I did some research on Google and here but didn't find any plugins or ways to do this.
I'm using 'Gridster' at the moment which this Gridstack is built off of/inspired by, so it probably won't be able to save for you.
You'll need to do that, either by sending it back via AJAX or storing in local storage. As it looks similar, you should be able to find a 'serialization' function which should wrap it up ready for you to send to your PHP via AJAX.
You may need to scan through the widgets and wrap them up in your own JSON string, such as the row/column/sizex/sizey which is all the grid system really needs to "add" a widget when its first loaded up, so as long as you can feed that back in you should be good to go.

PHP/MYSQL to create similar posts type script (similar images)

I am a beginner at using mysql/phpmyadmin, and have never used a cms before. I'm trying to get my head around how I could possibly add a 'similar posts' type script - but instead of showing posts, I would like to show some similar images (similar projects) when viewing each project page of my website.
My website setup is fairly simple:
main html page
profile html page
portfolio php page -> has thumbnail images with links to php generated url project pages
project page -> a dynamic php page that generates pages from pagination
contact html page.
The project php page has a jquery slideshow, project title and project overview text. The page uses three sql database tables for the data (slideshow images/text, page id for the pagination and one for normalisation), and uses pagination to change the data, creating a page for each project.
I'd really appreciate any ideas/opinions on how I could go about doing this - with sql, or am better off using a CMS (if so, do you know of a really simple one that could suit my website setup?).
If you're mainly wondering how you determine similarity, then you can do that with a text search in MySQL. I also found this page if you want to go to the trouble of building a tagging database schema. The former is simpler, but the latter is a really useful if you want to practice joins.

How to Have Search Engines Index Database-Driven Content?

How can I make it so that content from a database is available to search engines, like google, for indexing?
Example:
Table in mysql has a field named 'Headline' which equals 'BMW M3 2005'.
My site name is 'MySite'
User enters 'BMW M3 2005 MySite' in google and the record will show up with results?
Google indexes web pages, so you will need to have a page for each of your records, this doesn't mean to say you need to create 1,000 HTML pages, but following my advice above will dynamically / easily provide a seemingly unique page for each product.
For example:
www.mydomain.com/buy/123/nice-bmw-m3-2005
You can use .htaccess to change this link to:
www.mydomain.com/product.php?id=123
Within this script you can dynamically create each page with up-to-date information by querying your database based on the product id in this case 123.
Your script will provide each record with it's own title ('Nice BMW M3 2005'), a nice friendly URL ('www.mydomain.com/buy/123/nice-bmw-m3-2006') and you can include the correct meta information too, as well as images, reviews etc etc.
Job done, and you don't have to create hundreds of static HTML pages.
For more information on .htaccess, check out this tutorial.
What ILMV is trying to explain is that you have to have HTML pages that Google and other search engines can 'crawl' in order for them to index your content.
Since your information is loading dynamically from a database, you will need to use a server-side language like PHP to dynamically load information from the database and then output that information to an HTML page.
You have any number of options for how to accomplish this specifically, ILMV's suggestion is one of the better ways though.
Basically what you need to do first is figure out how to pull the information from the database and then use PHP (or another server-side language) to output the information to an HTML page.
Then you will need to determine whether you want to use the uglier, default url style for php driven pages:
mysite.com/products.php?id=123
But this url is not very user or search engine friendly and will result in your content not being indexed very well.
Or you can use some sort of URL rewriting mechanism (mod_rewrite in a .htaccess file does this or you can look at more complex PHP oriented solutions like Zend Framework that provide what's called a Front Controller to handle mapping of all requests) to make it so that your url's look like:
mysite.com/products/123/nice-bmw-m3-2006
This is what ILMV is talking about with regard to url masking.
Using this method of dynamically loading content will allow you to develop a single page to load the information for a number of different products based on the Id thus making it seem to the various search engines as though you have a unique page for each product.

Categories