Leave web page text manageable

Asked

Viewed 281 times

2

I developed a one-page layout which the client requested that a part of the site be manageable, something that was not in the project at the beginning.

It’s a simple line between <p> and </p>

What’s the easiest way to do that?

PS: I don’t work with PHP

  • The texts/sections would be fixed for example, header, menu text, main div text, footer?

  • That’s right, there is a part of the site that has a text and an image, and the client wants to leave manageable. ONLY this part, the rest is all fixed same.

  • If you only work with HTML and don’t want to work with the server-side (PHP, Node.js, etc.) I’m sorry but this is impossible unless your client knows html and FTP.

  • He does not know. Has how to do this via Wordpress?

  • @Felipestoker does, but you have to know a little PHP and a database access to save the paragraph. I don’t handle WP so I don’t know very well the structure unfortunately. but I think a simple answer explaining step by step can arise. Do you have access to the hosting account? will be necessary for the database..

  • I have access to FTP yes, I have Wordpress and BD installed and configuring pulling the data, just do not know how to do this =/

  • You can post as answer yes. Anything, I ask there

  • Maybe you could create a TXT on the server containing the text that will be in this paragraph then add an insert via PHP

  • 2

    Felipe, please prefer [Dit] the question to add details. We should not need to read the comments to understand the situation.

Show 4 more comments

2 answers

6


Do with Wordpress can be a bit like putting a tractor where needed a VW, but usually this kind of thing tends to escalate: today is a small text, tomorrow are five texts and some images, and so on.

In Wordpress, give the customer an account with role of Author. Using this account, log in and prepare a post that will be what the client will update. With the plugin Allow hide all that is superfluous for a basic level user.

To pull the content of this specific post in Wordpress, I would recommend the plugin JSON REST API and your favorite PHP or Javascript technique to popular your HTML. With it installed, use the URL http://exemple.com/wp-json/posts/{post-id} with the client post ID to receive a JSON object with the post content.

Here is an example of making an AJAX request to a blog that has the JSON REST API enabled using pure Javascript. To use with jQuery, search here in these search results.

/**
 * Faz chamada AJAX a um blog que tem o REST JSON API ativado
 * - busca por um post determinado ao iniciar
 * - oferece possibilidade de pedir outros IDs
 *
 * Inspirado em http://www.tutorialspoint.com/php/php_and_ajax.htm
 *
 * @param iniciar Boolean Usando para inicio da página ou envio do formulario
 */
function ajaxFunction(iniciar) {
  var ajaxRequest,
      ajaxDisplay = document.getElementById('ajaxDiv');;

  try {
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer Browsers
    try {
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        // Não tem jeito
        alert('Seu browser quebrou!');
        return false;
      }
    }
  }
  // Função que recebe retorno do Ajax
  ajaxRequest.onreadystatechange = function() {
    if (ajaxRequest.readyState == 4) {
      var parsed = JSON.parse(ajaxRequest.responseText);
      // console.log(parsed);
      ajaxDisplay.innerHTML = '<h1>' + parsed.title + '</h1>' + parsed.content;
    }
  }

  if (iniciar) {
    ajaxRequest.open("GET", "http://megane-blog.com/wp-json/posts/1400", true);
    ajaxRequest.send(null);
  } else {
    ajaxDisplay.innerHTML = 'Esperando JSON...';
    // Capturar valor e fazer chamada Ajax
    var post_id = document.getElementById('post-id').value;
    ajaxRequest.open("GET", "http://megane-blog.com/wp-json/posts/" + post_id, true);
    ajaxRequest.send(null);
  }
}

// Roda script ao carregar a página
ajaxFunction(true);
<form name='myForm'>
  Usar estes IDs como teste: 1377, 1366, 1355, 1331:
  <input type='text' id='post-id' />
  <input type='button' onclick='ajaxFunction()' value='Fazer AJAX' />
</form>
<div id='ajaxDiv'>Esperando JSON...</div>

  • The question questioner does not know mecher with PHP (but maybe you know js?), I think cool serial give a basic example of a file that pulls data via ajax to it.

  • 1

    @Olimon, better a jQuery then... I can even set an example, but maybe it’s better to wait for Felipe’s feedback.

  • Thank you very much for the answer. I will analyze it better and try to conform the answer. However, if it can be in JS, it is easier, I believe.

  • @Felipe, I put an example and an avenue for jQuery.

2

Felipe, no way, you can use a "Ferrari" to solve a simple problem, that would be Wordpress in the similar molds that the brasofilo answered, or you create a very simple own resource, which is the purpose of this my answer.

So I leave here for you to choose the best way. Seeing the comments if you want to use JS, in any case a PHP to persist the data in the database, via AJAX (there are other features for BD recording, but it is not ideal in this case).

I want to give this option to you in two steps:

1. A Jquery plugin for you to be able to edit inline text, that is, on the same screen as you are viewed content:

2. It’s no use the above feature if anyone can edit, so I recommend reading below to create a very simple PHP authentication system. In your case, after authenticated, return to the normal site screen, but enabling the editing events through the above plugin. Follow the tutorial:

3. PHP files that "will receive AJAX". Respecting and understanding items 1 and 2 you will be able to do this step without problem.

I hope I gave you a valid option for your project. Hugs.

Browser other questions tagged

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