Hey.

There is a code, it displays the text up to the more tag from the page I specified to the main page.

<?php global $paged; if(is_home() && $paged == "") : $my_query = new WP_Query('pagename=страница'); // тут надо указать название требуемой страницы while ($my_query->have_posts()) : $my_query->the_post(); the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); endwhile; endif; 

Question:

how to rewrite the code so that it displays part of the text after the more tag with an anchor an id . That is, the segment, which has an anchor id c name . There are only 2 such bindings on the page after the more tag, they need to be displayed in separate divs.

Looks like that:

 <h1>Заголовок</h1> <p>текст</p> <--more--> <div id="1"><a name="1"></a></div> <h2>Заголовок 1</h2> <p>текст</p> <div id="2"><a name="2"></a></div> <h2>Заголовок 2</h2> <p>текст</p> 

The main page should display text with id = "1" in one block, and the text from id = "2" into another div block.

    1 answer 1

    Add before request:

     global $more; $more = 0; 

    Well, after that, remove the text with a regular schedule:

     preg_match_all("##", $my_query->the_post(), $result); $array_blocks = array(); for($i=0; $i < sizeof($result[0]); $i++) { // номер блока // содержимое блока $array_blocks[$result[1][$i]] = $result[2][$i]; } 
    • lampa did not work, the block is empty. - Viher
    • @Viher, sorry, I forgot about the regular schedule, it should be like this: preg_match_all ('# <div id = "([0-9] +)"> <a name="[0-9++> (. *?) < / a> </ div> # ', $ my_query-> the_post (), $ result); - lampa
    • The text appeared before the tag more. <div id = "([aZ] +)"> <a name="[aZЗ+"> (. *?) </a> </ div> - Viher
    • lampa Why does the query display text before the more tag? if (is_home ()): $ my_query = new WP_Query ('pagename ='); while ($ my_query-> have_posts ()): $ my_query-> the_post (); global $ more; $ more = 0; the_content (__ ('Continue reading <span class = "meta-nav"> & rarr; </ span>', 'twentytwelve')); preg_match_all ('# <div id = "([az] +)"> <a name="[az[+"> (. *?) </a> </ div> #', $ my_query-> the_post ( ), $ result); $ array_blocks = array (); for ($ i = 0; $ i <sizeof ($ result [0]); $ i ++) {$ array_blocks [$ result [1] [$ i]] = $ result [2] [$ i]; } endwhile; endif; - Viher