Leave manageable site text

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 first.

It is a simple line between <p> and </p>

What's the easiest way to do this?

PS: I do not work with PHP

    
asked by anonymous 27.10.2014 / 23:10

2 answers

6

Doing with WordPress can be a bit like putting a tractor where you needed a fusca, but usually that sort of thing tends to escalate: today is a small text, tomorrow are five texts and some images, and so on. p>

In WordPress, give the customer an Author role . Using this account, log in and prepare a post that will be what the client will update. With the Adminimize plug-in, hide everything that is superfluous for a first-level user.

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

Here is an example of doing 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>
    
28.10.2014 / 00:24
2

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

So I leave here for you to choose the best way. Viewing the comments, if you want to use JS , you will still need a PHP to persist the data in the database via AJAX in> (there are other resources for writing to BD, but it is not ideal in this case).

I want to give you this option in two steps:

1. A JQuery plugin for you to edit the inline text, ie on the same screen as the content you are viewing:

2.

In your case, once authenticated, it returns to the normal website screen, however enabling editing events through the above plugin. Here's the tutorial:

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

I hope I have given you a valid option for your project. Hugs.

    
28.10.2014 / 12:55