How to "creating new page" works in PHP? - php

Page creating in PHP: I'm trying to learn how to make a cms but I couldn't understand something. For example in Wordpress when you click "create a new page" button what is happening at the backside? For example now I don't have any page.
I want to create these pages dynamically:
Home
About
Contact
After I want to add this pages in my menu. What is the best way to do that?
Questions:
Should I create a new php file to do this or just get data from my database which belongs to each page?
How I add these pages in my menu dynamically ?
What is htaccess? I couldn't understand that exactly it does relating the the processes of the files.
There are tutorials on internet but they always show how to get articles from database. When I have another item (for example a slider) I need a real page.
Can somebody suggest me a simple tutorial, or provide a clear explanation which explains the logic simply.

I have created something similar. This is how I did it (may not be the best way but it is certainly the easiest).
Create a template file and insert tags (!Title!, [[Title]], etc) where you want the new pages data to be inserted.
When creating a new page, read the contents of the template and replace the tags with the data submitted (I used titles, desc, h1, etc but this can also be achieved through a simple content function)
The user selects/creates the directory using mkdir()
All this is then stored in DB ready for the user to navigate to.
You can then use the DB entries to build a navigation menu

Related

How to update the content of a website using the website itself?

Is it possible to update the content of a website (add Item, remove Item, update Infos, etc...) directly from the webpage?
For example, you have a webpage and you make a new page in it, that only the admin can access. That page should contain some options that allow the admin to change/update contents on the actual website(what people can see) easily.
(Without the admin having to write new HTML or PHP code...)
I heard something about Joomla or Wordpress but I don't really know how they work.
Thank you.
Basicaly, joomla has some fonctionnalities to edit content by the frontoffice. Of course, the user need to be logged and access levels need to be well managed. You should to try it with a basic installation and see if it's coherent with respect to that you looking for.

Dynamically Creating pages based on user's input

I have an article website. So far, all my articles have been created by me working with the code. Copying and pasting the code and editing the P tags, H1 tags, etc. This turns out to be a hassle and increases the chance of you making an error. Especially when the article has multiple pages.
Future-wise, I want users to create articles. So this is what I want: User clicks on button that says 'create an article' and then the user gets redirected to the article builder page where they can make an article for themselves. The user will create a name for their article, this name will create a folder on my server...for example: www.example.com/articles/name-of-article. Then the user can write the article. The user will abide by classes I have created for tags, but those tags will not be seen by the user. The user only sees that their content is getting adjusted well based on my CSS template. Also, if the user wants to add another page to the article, they can put in already built buttons...they just have to change the links to those buttons. The user should also have the ability to bold, underline, and italicize text.
Note: Users are working with a pre-built template, not a blank page. The template article includes a recommended panel, showing other articles. The user does not have permission to edit this panel.
I've heard about WYSIWYG HTML editors, but I just want to know if this is the right thing for what I want. Is there something else that can accomplish my task better? If WYSIWYG is the best answer, can it do everything I've asked for?
P.S: My article pages are PHP pages, with HTML and Javascript included.
You don't need to write html codes of articels in php. I would suggest you to use a content management system (CMS) like Wordpress.
What you want is a CMS. Wordpress is the best approach for your needs, but if you can't use it, you can search for other CMS systems/frameworks.
If you want to make/use your own, just remember to do a Template framework.
And appart of your main question about WYSIWYG, yes, you can do all you asked if it can be done with PHP.

WordPress - Get all of current page's queries information

Okay... so here is what I'm trying to do. Basically all of the components that make up any particular page on a Wordpress site, I need to be able to grab the query that WP is running to grab the data for that particular area of the given page. So, if we have page A, let's say it has a top navigation, main content section, and footer. Each of these three areas have content that is pulled from the database. I need a generic way to say on page X I want to know what queries have been ran to generate all of the content pulled from the database and displayed on the page.
I feel like the key is to properly use https://codex.wordpress.org/Class_Reference/WP_Query to get the data I need.
Any thoughts on how I could go about this?

Insert .php file in another .php file and only execute a function()

I know the title is messed up, but basically I have: news.php which is kind of a dashboard where I get all news from DB and I can perform actions on them (update, delete, insert new) and also I display them in a traditional way (tables). The problem is I want the title of the first news to be displayed on my homepage(footer), but when I include the news.php file withinclude(), the hole code it's included and on the home page I get all the things I have in news.php, all the news, the buttons (edit, add, delete) and everything else. Is there any way of including one .php file but not displaying it ? I want to create a function that only displays the title of the first news but I can't because the hole code is imported and displayed.
Thank you for your quick answers. Having only this small problem, I'll just create another file where I get the latest news without using frameworks
You need to create a function library so that you can call specific segments if you want.
But here's a quick shortcut. copy news.php into news2.php. go into news2.php delete all the parts you don't want; include news2.php instead
You could try making another single file called firstnews.php which would only retrieve that particular first news item and include that.
You should maybe read up on MVC frameworks, its a good way to seperate data retrieval, manipulation, and then actually showing the data. For example one php file would hold a function that retrieves all news item, and another function that only gets the latest news article. Then the actual file which shows the user data would simply choose which function it wants to use.
Its a lot to get into, but the codeigniter framework is a great way to get familiar with MVC frameworks and it will open a lot of doors for you.
CodeIgniter Homepage
Manual on how to setup and use CodeIgniter
For now though try just making a seperate php file that only retrieves the latest news item instead of all of them and include that.
Hope this helps!
-Gui

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:
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.
u can find how to create plugin from
http://ditio.net/2007/08/09/how-to-create-wordpress-plugin-from-a-scratch/
in plugin write function for search(as per u r logic) fetch result
create a custom page refer video from www.wordpressmax.com/customize-wordpress/custom-page
in custom pages template in between get_header(); and get_footer(); call search function and display records.
Thats it.
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.
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.

Categories