User's way to include new pages in a site without programming

3

Just like in WordPress you have the option of creating, editing, displaying and editing pages

I know I can use WP, but for learning I would like to do programming.

I'm trying to develop a function in my panel that should have the option to create page, when clicking this option it brings me the input type=text field to put the title of the page, the editor (tinyMCE or CKEditor), like of image:

Forexample:inthisareaofWPyouhavetheoptionofeditinganddeleting

These prints are from Wordpress.

In the backend, how do you do this encoding: I know that this information when passed is sent to the bank when it is generated. I also have the option to create a menu, everything is linked.

Front-end, when the client accesses the site there is the menu and when clicked on the menu appears the content that is rescued from the bank.

In this process, I know how to make the administration page to save, edit and delete, make the menus and link them to the bank.

The problem is just on the other side. How do I display these files and menus in the template for the user? Example:

index.php?page=home , index.php?page=empresa , and index.php?page=sobre index.php?page=contato? (these pages exist).

Let's assume that my client has the site as above (he does not know how to program a line of code) and he wants to create a page on the site, for example, so that it looks like this: index.php?page=galeria , hence he goes in administration and create, to then appear the page and the respective menu that he created.

I need to do a loop function that, "I think", is checking in the direct bank for whenever it has a new menu in the menu table (for example) it makes the display in nav of the site, with a conditional to only display if this menu has a content and this reference to some content (it would be the page content) that it will print on the screen for the user.

That's what Wordpress does, right? How do you do this encoding? I have the logic just do not know how to use it.

I'm confused on how to display this content (from the new page of the example I gave above) formatted on the screen for the user as well as the other pages I already had on the site.

    
asked by anonymous 19.09.2014 / 17:05

3 answers

2

Well, let's see if this is what you want ...

You will have a DB like this (+ -):

    //tabela paginas:
    //(id, nome, conteudo);

when it inserts a new page:

    //(1, galeria, conteudo1);

In the index you can do this:

    <?php 

    $get_page = $_GET['page'];

    if(isset($get_page)){


    $selecionaPagina = mysql_query("SELECT * FROM paginas WHERE nome = '$get_page'");
    while($paginaConteudo = mysql_fetch_array($selecionaPagina)){

    }


    ?>

    // ai você faz o loop

    <div><?php echo $paginaConteudo['conteudo']; ?></div>

    <?php } ?>

Already in the menu, you would have to do the same thing, but selecting only pages with content

    <?php

    $selecionaPagina = mysql_query("SELECT * FROM paginas WHERE NOT conteudo = ''");
    while($paginaConteudo = mysql_fetch_array($selecionaPagina)){

    // ai você faz o loop

    <ul>

    <li><?php echo $paginaConteudo['nome']; ?></li>

    </ul>

for static pages, or you change instead of index.php? page = contact for contact.php or you create arrays of them and do an initial check in the index. Type, if the $ _GET ['page'] exists and it is = the contact: include ("contact.php");

I hope to have helped

    
19.09.2014 / 22:02
2

You should work well on your database structure to have a legal result, easy implementation and maintenance. Here I am illustrating a simple but powerful modeling.

Just study the modeling well, and perform the queries correctly. To display the content you must have a page that always searches for the "page" you want and display the content of the page with echo .

Bank modeling

Menu table ( navs )

  • id (unique, auto_increment)
  • name (NOT NULL)
  • description
  • slug (single NOT NULL)
  • active (1 - Active, 0 - Inactive, Default 0)
  • menu_id (foreign key).

Records

(1, 'Home', 'Página inicial', 'home', 1, 1)
(2, 'Contato', 'Página de contatos', 'contato', 1, 1)
(3, 'Site map', 'Mapa do site (menu do rodapé do site)', 'site-map', 1, 2)
(4, 'Contato', 'Página de contatos (menu do rodapé do site)', 'contato', 1, 2)

OBS: The field slug is what you will pass in the links for page search, so it should always be unique as a primary key, and it is recommended to index it.

Menu group table ( menus )

  • id (unique, auto_increment)
  • description

Records

(1, 'Menu Principal')
(2, 'Menu Rodapé')

Page table ( pages )

  • id (unique, auto_increment)
  • title (NOT NULL)
  • content (NOT NULL)
  • description
  • keywords

Records

(1, 'Home', '<p>Conteúdo da página</p>','Essa é a página inicial do site','página, inicio, home, site, foo, bar')
(2, 'Contato', '<p>Página de contato</p>','Essa é a página de contato do site','página, contato, contact, site, foo, bar')
(3, 'Site Map', '<p>Mapa do site</p>','Essa é a página com o mapa do site','página, map, site map, mapa do site, mapa, site, foo, bar')

Table of relationships between menus and pages (one page can have multiple menus, but one menu only once) ( navs_pages )

  • id_nav
  • id_page

Records

(1,1) // Menu principal -> Página Inicial
(2,2) // Menu principal -> Página Contato
(3,3) // Menu rodapé -> Site Map
(4,2) // Menu rodapé -> Página Contato

Search for menus

$sql = "SELECT n.* FROM navs n WHERE n.id_menu = 1 AND n.ativo = 1;"; // Menu Princial
$sql = "SELECT n.* FROM navs n WHERE n.id_menu = 2; AND n.ativo = 1"; // Menu Rodapé

// Aqui você tem a lista dos menus é só trabalhar neles para montar o HTML

Search for pages

$page = (isset($_GET['page']) ? $_GET['page'] : 'home');

$sql = "SELECT p.* 
        FROM navs n
           INNER JOIN navs_pages np ON (np.id_nav = n.id)
              INNER JOIN pages p ON (p.id = np.id_page)
        WHERE n.slug = '{$page}'"

// Executa essa consulta SQL e da um echo do conteúdo no local desejado
    
22.09.2014 / 15:01
1

Let me see if I get it, you want to make a web application that creates and manages content, a CMS in this case.

Look, if it is, there are some materials that can help you. Quick search on Google found this, also in PHP:

CMS with CakePhp

The interesting thing about this article is that in addition to using PHP, it uses a framework to work with MVC, which would make it easier to encode.

What you're trying to do basically consists of storing the HTML that the user types or his editor generates in the database, and in a PHP script, via $_GET['paginaexemplo'] , you load this information from the database and put it in some part of the merged PHP code with HTML, which would generate your code below, eg: index.php?page=home, index.php?page=empresa e index.php?page=sobre index.php?page=contato? (these pages exist).

The advantage of using a PHP framework such as CakePhp is that it offers a number of features you would not have to do.

    
19.09.2014 / 17:38