P
P
Pseudoquater2022-02-09 06:34:34
PHP
Pseudoquater, 2022-02-09 06:34:34

How to insert text after Nth paragraph?

How would the code below change (to insert text in specific paragraphs) if instead
of calling content: the_content();
content will be called by another command: get_template_part( 'content' );

<?php
    // Вставка любой информации после второго абзаца
    $paragraphAfter = 1; // После какого абзаца нужно вставить в первом блоке
    $paragraphAfter2 = 3; // После какого абзаца нужно вставить во втором блоке
    $content = apply_filters( 'the_content', get_the_content() );
    $content = explode( "</p>", $content );
    for ( $i = 0; $i < count( $content ); $i++ ) {
        if ( $i == $paragraphAfter ) {
            ?>

    <p class="combo"> <?php the_field('text1'); ?></p>

<?php
 } else {
        if ( $i == $paragraphAfter2 ) {
?>

    <div class="combo2"> <?php the_field('text2'); ?></div>
   
    <?php
    }}
    echo $content[ $i ] . "</p>";
    }
                  
   ?>

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
mletov, 2016-02-03
@mletov

To get started, read about normal forms (at least the first three) and why you should use normalization.
When you understand, read the cases in which it should not be used.

H
hail3b, 2016-02-03
@hail3b

Firstly, you need to learn how to ask questions, or rather format them, in your question the table structure is unreadable.
Secondly, there is a lot of literature on the net, choose the latest and go ahead. Technical literature does not need to be read sequentially; if you are familiar with the chapter, read the next one. You cannot find an individual book for your project; there will always be something "extra".
Thirdly, you need to decide on the priority of the task, the speed of execution or interest / self-education. For a beginner and not only, these are two opposite priorities and the execution plan will be different. If this is an order and you need to do it faster, then take a ready-made engine and set it up for yourself. If you are interested in the process of designing a database, then do everything yourself. The finished project is also not worth taking. you need to understand it and it will seem very complicated to you.
Regarding your question:
There is an error in your structure, in each table there is a login field and there should be an id link to the login table. The database structure in your case will be something like this:

-- Пользователи
CREATE TABLE user AS(
  id int identity,
  name varchar(128),
  pass varchar(128)
)
-- Авторизация / сессия
CREATE TABLE user_session AS(
  id int identity,
  user__id int,
  timestamp datetime
)
-- Сообщения
CREATE TABLE message AS(
  id int identity,
  post__id int,
  user_session__id int,
  subject varchar(255),
  text varchar(max)
)
-- лайк / дизлайк
CREATE TABLE message_like AS(
  id int identity,
  user_session__id int, -- пользователь кто плюсанул
  message__id int,
  value int -- плюс 1 / минус 1
)

A
Anton Natarov, 2016-02-03
@HanDroid

And you can go even faster way, but then you will not learn how to design.
Google Blog/Store/Cinema Database Architecture and so on.

I
Ilya Trusov, 2016-02-03
@artgrosvil

Google the DB textbook, not the architecture one. Judging by the way you have described your question, you are way too early for the architecture. And the very understanding of "architecture" will come with experience.
Then use this tool or similar dbdesigner

K
kretsu, 2016-02-04
@kretsu

I don't think it's right to start a project with a base design.
First describe the objects that you will operate on: user, topic, message, etc.
Describe all the properties of the objects
Next, describe the relationship between them
Then write usage
scenarios I propose to try UML first
. And then you can already try to map it all to the base. On the other hand, modern frameworks allow you to do this automatically. It often turns out to be garbage. But everyone does not care about this, as long as it works and does not slow down.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question