I'm currently have around 100 rows in a table on my website, which include a URL and few sets of numbers pulled from a database on my server. What I would like to do is to dynamically create pages based on a cell of each row, which would contain data pulled from the same database. For example, each row (displayed in the table) would look like this:
Icon (url) | Name (url) | Number 1 | Number 2 | Number 3 | Number 4 | Number 5
Inside my database however, each row is like this:
Icon (url) | Name (url) | Number 1 | Number 2 | Number 3 | Number 4 | Number 5 | Description (large body of text) | LargeImage (url)
Since I have so many entries, I would like to be able to have some way to generate the pages based on the name of the row in the database (it would take too long to make each page individually, and I will be updating this table frequently with content), so I can display more of the information out of the database row (the description, largeimage etc) that I wouldn't be able to fit into the table.
Are there any plugins for Wordpress that can do this, and if not, how would I go about doing this in PHP?
I'm not sure how to best integrate this into WP, but it's fairly straightforward in PHP. You just have a file like mypage.php?id={#} where the # is the individual record's ID. You pull the ID using GET ($id = $_GET["id"];) and then run an SQL query with it as the WHERE, take the results and populate the page with that row of data. Then, using .htaccess, you can do what WP does and make this look like a URL (ie. mypage/2/).
You can create the custom page by using a method like this for example.
You could integrate this into WP by creating a separate file (other than single.php, for example) that would run this PHP script, but include the WP header and footer to make it fit into the theme. However, this wouldn't really be fully integrated into single.php and therefore wouldn't appear in the posts section in the admin or anything. Is that a requirement?
Related
I have made a CMS using PHP and MYSQL for the back-end. The problem is, I'd like to have the site available in multiple languages; So I've already translated the CMS itself and put it in files like:
en.ini
nl.ini
Which works fine for the CMS' contents itself, like the Administration etc. The actual problem occurs when I try to translate the website further: The blogposts and pages are stored in a database, so they're dynamic. My pages table's structure looks like this:
urlname | name | id | content | position | hidden | redirect | type | permission
So, if I were to translate a page into, for example, Dutch, I don't want to create a new table called pages_nl for example, because most of the information would be the same as the other table.
I could add a row which contains the page's available languages, and make php read the array and parse if the current $lang matches one of the page's available languages, and then read the content_nl and name_nl row as an example.
The same problem would occur with my blog posts, and I have searched for a solution, but most results were for specific CMSs and just plugins.
I'm asking what would be the best way (and database structure) to store multilingual pages/posts, where languages could be added dynamically and have a fallback on the original content if there's no translated version available.
Basically you add a lang-key to your database
urlname | name | id | content | position | hidden | redirect | type | permission | lang
Now lets say a request comes for a page with 5 content elements in it. Your CMS first search for the entries with the specific lang-code, for example nl. If it dont find an entry with the language code it falls back to the default language and take that entry.
Let say you have translated Content 1, 3 and 5:
Content 1 Content 1 nl
Content 2
Content 3 Content 3 nl
Content 4
Content 5 Content 5 nl
Result:
Content 1 nl
Content 2
Content 3 nl
Content 4
Content 5 nl
Another way would be to do the translation in the template files (like magento does it).
In magento you have something like that:
"Hello, this is the " . $this->__("English") . " page"
And translation files. For example lang.nl:
"English", "Dutch"
In this case you will have only 1 Content Element, but you will wrap every element that shall be translated. This also works with images and everything you want. You can also abstract this wrapper to work in a backend RTE-Editor. For example, you will write Hello, this is the English page in your backend then mark Englishand click the translation button. This will add a Tag around English and when you render the content you scan for this tags and replace it if you find any translation for this string in the requested language.
I'm beginning web development and started using PHP and MySQL. I'm trying to make a CMS similar to a technical blog and stuck at database design. Each post can be of any one of the following type.
Rich text - Single part
Rich text - Multiple parts
Video link - Single part
Video links - Multiple parts
Attachment - Single part
Attachments - Multiple parts
(The attachments can be pdf, doc, ppt)
Each post is under section. The sections are stored in a table. Examples for sections are
Tutorial - all types are allowed
Code snippet - only 1 is allowed
Tips or hacks - only 1,2,3,4 are allowed
News update - only 1 and 3 are allowed
Review - only 1 and 3 are allowed
So my question are
How do I store and distinguish single and multipart posts?
What is the feasible/best way to store attachments?
How do I relate sections and posts? ie., How to know/store that a particular section can support post types(all, only 1, only 1 and 2, etc).
Edit:
By single means, I mean 1 post has only 1 part and by multipart I mean 1 post can have several parts
I guess with "single" you mean that one post is related to one section, multipart means several posts relate to one section?
db-design could be...
table section
---------------
id (int, a-i)
type (int) 1=tutorial, 2=code-snippet etc.
name (varchar)
...
table post
---------------
id (int, a-i)
section_id (int) key to section.id
ordering (int) if multi for controlling which part is first, second etc.
type (int) 1=rich-text, 2=video, 3=attachment <---- drop single/multi discrimination here
single (int) 1=yes, 2=no <---- and put it here instead
content (varchar) --> see below
description (varchar) of this post
note: a single is one post, a multi several post linked to the same section.
where to store attachments:
in the file-system of your web server, the db holding the file-name in table.content.
small post-types (e.g. a link) can be stored directly in table.content
--> keeping your db lean and performing
relating sections and posts:
by post.section_id. Like this, you can link 1 or more posts to a section. use post.ordering to put them in the right order.
section
--------------------------
id | 1
name | "How to build a CMS"
type | 1 (tutorial)
post
--------------------------
id | 1
section_id | 1
ordering | 0
type | 1 (rich-text)
content | "/files/130224_1_1_cms.rtf"
...
id | 2
section_id | 1
ordering | 1
type | 3 (video link)
content | "http://www.youtube.com/hgstersh/showid=23jfjr&blabla"
...
which section.type can have which post.types?
on creating a new section, the section.type is set (e.g. drop-down-list in a form)
on creating a new post for this section, the drop-down-list for post-type offers only permitted types based on section.type, this is done in the php-script with if... or switch...case.
If a post can have multiple images, posts, links that's a one-to-many relationship and the typical schema is:
POST: id, title, ...
RICHTEXT: id, post_id, content
LINK: id, post_id, url
If you need a many-to-many relationship, for example a story can have many links but the same link can be on multiple stories you would have:
POST: id, title, ...
LINK: id, url
POSTS_LINKS: id, post_id, link_id
Also take a quick look at schemas for other popular platforms
I'm working on one project and having problem with obtaining data from mysql to website and from website to mysql.
It's about getting data from mysql--> rotate data(to pick one value of more)--> show this on website--> count visits and if someone click on some link, track it as +1 to database.
Mysql design for better understanding:
Campaigns Table
-c_id 1 2
-name Campaign 1 Campaign 2
Parameters Table
-p_id 1 2
-name Title Image
-c_id 1 1
Variations Table
-v_id 1 2 3 4
-variation Welcome1 Welcome2 img1.jpg img2.jpg
-p_id 1 1 2 2
-c_id 1 1 1 1
So when php/js file is called it should return 1 variation(Welcome1 or Welcome2 for parameter Title with id 1 and img1.jpg or img2.jpg for parameter Image with id 2) of all parameters(Title, Image).
This data should be added to website with php echo or js document write. (php echo $parameter1; ).
After that there should be onclick on link/s so I can track with which combination user clicked on link. Problem I'm facing here is I don't know how to get and pass which elements was show on website(which variation) and also how to pass.
This will not be placed in same folder and domain as website. Only the server will be same. So I think there won't be problem with accessing database.
I'm not asking for full code of anything just for ideas how to make it the simplest way and also effective.
The database looks a little strangely built, but if that suits you then it should be fine. There are also some other things missing and I am not sure what you are trying to accomplish.
But, when passing the parameters to JS or PHP also pass the ID of the variation, not only the value. When you pass the parameters pass
Title = Welcome1
TitleId = 1
Image = img1.jpg
ImageId = 3
When you create the link that will take you to the other page you should create it passing to it the 2 parameters link?TitleId=1&ImageId=3
In the page that gets process with link count that the visitor got there by pressing on a link with TitleId=1 & ImageId=3
For a project I am making I need the possibility (like stackoverflow does) to save all the previous edit (revisions) for posts.
Consider I can have some 1 to N association with the post (for example 1 post with 5 images associated).
How would you suggest me to design the database for this?
Of course the ID of the post should stay the same to don't broke URLs:
site/post/123 (whenever revisions it is)
Each revisions to posts should be manually approved so you can't show directly the last revisions inserted. How would you suggest me to design the db?
I have tought
Table: Post
postID | reviewID | isApproved | authorID | text
And the image table (for example image, but it could be everything)
Secondary Table: Image
imageID | postID | reviewID | imagedata
Actually, I would split the post table in two, with the approved revisions in one, and the latest (not approved) revision in another. The rational is that any non approved revision which is not the latest would be supersceded by the next one (unless you really want to keep track of all the intermediate modifications, approved or not).
Table: OldPost
postID | reviewID | authorID | text
Table: PendingPost
postID | authorID | text
In that layout, whenever a new revision has been approved, it must be moved to the approved ones, but you don't have to filter them out when displaying the whole history, and conversely, you wont have to filter the approved revisions in the approval part of your site.
You could even refine the layout with yet another dedicated table for the latest approved revision (so three tables for the post in total, not counting attachements). This partitioning would improve the overall performance of your site for the most common queries, at the cost of more complex queries when you need all the data (less frequent operations).
Table: CurrentPost
postID | authorID | text
As you can see, this table structure is the same as the one for pending posts, so the updates would be trivial.
moving a revision to the old post table requires to find out the revision count, but you would have to do that operation anyway with a more classic db layout.
Regarding the attachment table, the layout seems to work.
Separate all aspects of a post between global information and versionable information. In other words, what things can be changed in a revision and what are always going to apply to any revision. These are going to be the fields in your two tables, one for your posts, and one for the revisions. You will also need a row to specify what post the revision is for as well as whether the revision is approved, and on the posts table, you need a row to specify what the current revision in.
I am trying to figure out the best way to have a page dynamically know which data to output.
I have a index.php that I want to be able to pass some $_GET variables into it and then based on that know what to display. Aside from the content being different the type of the content is also different I have products and other types of pages like blog posts etc. The products are stored in different tables then the other pages. and also have a slightly different table structure as well.
currently I have the following tables.
Subjects, Pages and Categories.
Table = Subjects
id | menu_name | menu_number | category | menu_position | active
Table = Pages
id | subject_id | category_id | page_name
Table = Categories
id | category
These are the main tables that outline the main structure of the site. I then have secondary tables that contain the actual data for the pages.
posts, post_details, post_pypes and
products, product_details, product_types and product_specs.
What I want to active is that a variable will be send along in the query string and based on this the application will know what information to display .
My question is how can I make a table that will catalog all entries (posts and products) with a unique id and that will be the only variable needed to for my application to determine how to proceed. i.e. query the table int he database that is holding that unique id and tell the application its a "product" and the product id is X and to continue querying the needed tables for the info.
Thanks in advance.
I highly recommend looking into a secure, structured environment like CodeIgniter to accomplish whatever it is you are trying to describe above. The scope of that question is really broad which likely indicates that you would profit from a prebuilt framework of some kind.