User way to include new pages on a website without programming

Asked

Viewed 506 times

3

Just as in Wordpress you have the option to create, edit, display and edit 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 being clicked on this option it brings me the field input type=text to place the page title, the editor (the tinymce or Ckeditor), as in the image: add pagina

For example: in this area of WP you have the option to edit and delete

Opções

These prints are from Wordpress.

In the back-end, how to 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 lynched.

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

In this whole process I know how to make the page in the administration 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 user template? 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 the way above (he doesn’t know how to program a line of code) and he wants to create a page on the site, for example, so it looks like this: index.php?page=galeria, then he goes to the administration and creates, and then appears the page and the respective menu that he created.

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

That’s what Wordpress does, right? How does this coding? I have logic I’m just not knowing how to use it.

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

  • 1

    +1 by attitude ("mas por aprendizado gostaria de fazer programando.")

3 answers

2

You must work well in the structure of your database to have a legal result, easy implementation and maintenance. Here I am illustrating a simple yet 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 desired "page" and displays the content with a echo.


Bank Modeling

Menu table (navs)

  • id (single, auto_increment)
  • name (NOT NULL)
  • description
  • Slug (single NOT NULL)
  • Active (1 - Active, 0 - Inactive, Default 0)
  • id_menu (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 on the links to the search pages, so it should always be unique, as a primary key, and is recommended indexes it.


Group table of menus (menus)

  • id (single, auto_increment)
  • description

Records

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

Page table (pages)

  • id (single, 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')

Relationship table between menus and pages (one page may 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 the 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 the 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
  • Good tip I’ll try to implement, doubts put.

  • @Thanks! for the tip.

  • All right, I did the SQL on hand here and I didn’t test it, so if there’s a problem and you can’t figure it out then we’ll help you. If you manage to implement and find that this is the most appropriate question mark as accepted. ;)

2

Well, let’s see if that’s what you want...

you’ll have a DB like this (+-):

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

when he inserts a new page:

    //(1, galeria, conteudo1);

at index you can do so:

    <?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 the 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 do you change instead of index.php? page=contact for contact.php or you create arrays of them and do an initial check on the index. Type, if $_GET['page'] exists and it is = the contact: include("contact.php");

hope I’ve helped

  • I’ll test it. Thank you

1

Let me see if I understand, you want to make an application web that creates and manages content, a CMS in the case.

Look, if that’s it, there are some materials that can help you. Googling fast 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 facilitate its coding.

What you’re looking to do is basically store the HTML that the user types or your editor generates in the database, and in a script PHP, via $_GET['paginaexemplo'], you upload this information from the database and place it in some part of the merged PHP code with HTML, which would generate your code below, example: 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 framework PHP like Cakephp is that it offers a number of features that you wouldn’t need to do.

  • It would rather be a management of pages, so I want to implement in my dashboard, in case we assume that I have the administrative dashboard, with user control, posting, news, newsletter ... and I just want to implement the system to manage my pages(Create, edit and delete as the view will be made on the client side). That’s what I can’t do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.