K
K
Kirill Abdulov2020-04-28 15:36:54
WordPress
Kirill Abdulov, 2020-04-28 15:36:54

How to add html templates with modified text via WordPress admin panel?

There is a layout of one page, in this layout there is a slider with reviews from users and users, accordingly, can leave new reviews. This happens in such a way that the user writes a review in the form where he fills in two fields: full name, Review. After submitting the form, the data from the fields is sent to the mail, they look at this review and decide whether to add it to this slider or not. And with adding it to the slider, problems arise. Of course, you can copy the text of the review from the letter and write another slider block directly in the .php file, but with the corresponding text, but I think there is another way out. I am not strong in WordPress itself, but I am almost sure that there is such a method to write a review text in the admin panel and it will insert this text into the corresponding html template and add it to the right place on the page.

Those. in my meager view it looks like this:
I am writing an html template, in my view it looks something like this:

<div class="review">

    <div class="reivew-title>
        <div class="review-title-photo"></div>
        <div class="review-title-name"><?php esc_html($review_name); ?></div>
    </div>

    <div class="review-content">
        <div class="review-content-text">
            <?php esc_html($review_content_text); ?>
        </div>
    </div>
</div>

Then, in the admin panel, I write the values ​​​​of the variables $review_nameand $review_content_textthey are substituted for the desired one in the written template, and this template is inserted in the right place on the page.
And so, how can the above be done and is there such a thing at all? Or is there another way out for this, if so, what?

PS I googled a lot and only roughly understand that you can use shortcodes, but how to use it is also not very clear

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IvanMogilev, 2020-04-28
@IvanMogilev

You need to use a plugin, for example advanced custom fields, or carbon fields, they will allow you to fill in data in the admin part, and in the template you will use something like

foreach($reviews as $rev)
{
<div class="review">

    <div class="reivew-title>
        <div class="review-title-photo"></div>
        <div class="review-title-name"><?= $rev["title"] ?></div>
    </div>

    <div class="review-content">
        <div class="review-content-text">
            <?= $rev["text"] ?>
        </div>
    </div>
</div>
}

Read the plugin documentation, it's full of examples
https://www.advancedcustomfields.com/
https://carbonfields.net/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question