Support

Account

Home Forums Add-ons Flexible Content Field Pagination

Solving

Pagination

    • pixaro

    • November 20, 2013 at 12:20 am

    Hello,
    I wonder if there is a way to insert the native function wordpress <!– nextpage –> (to create a pagination) in WISIWYG flexible content field. That’s doesn’t work for me.

    Thanks

    • Elliot

    • November 20, 2013 at 10:00 am

    Hi @pixaro

    I have not yet tested this, but have a feeling that you could make it work as expected.

    You can hook into the WYSIWYG value through the filter called ‘acf_the_content’. This is a replica of the already WP documented ‘the_content’ filter.

    Using this, you could use some PHP to look for and explode the value based on ‘< !– nextpage –>‘. Then, using a the current paged query parameter, you could customize which part you return as the value.

    Hope that helps

    Thanks
    E

    • pixaro

    • November 20, 2013 at 3:42 pm

    Hi @elliot ,

    Thanks for your reply. In fact I think I expressed myself badly. I have a flexible field with subfields that manage my posts’ content. Is this possible with any means (adding a specific field or putting eg <!– nextpage –> in WISIWIG field) to separate the flexible field into multiple page?

    • Elliot

    • November 22, 2013 at 9:35 am

    Hi @pixaro

    I see, so this question is not specific to the WYSIWYG field? That is where your question became confusing.

    I would create a layout in your flexible content field called page_break.

    Then in your template, within the flexible content loop, create a counter variable which starts at 1 and gets increased each time the page_break layout is used.

    Then, you can look at the $_GET param “page” and match it to your counter variable value. If the value does not match, use a ‘continue’ statement to ignore the current loop’s layout.

    Therefore, if you had &page=2 in your URL, your loop would only show layouts which appear after the first ‘page_break’ but before the second.

    I hope that helps

    Thanks
    E

    • pixaro

    • November 22, 2013 at 7:17 pm

    Thank for your reply @elliot I will try this solution. I work on another solution but I do not know yet if it’s the most efficient.

    My solution is as follows:

    I create a “next_page” field. Whenever WordPress meets a flexible field, I increment my content in a variable $myContent.

    When WordPress meets a field next_page I do this:
    $myContent = "<--nextpage -->\n"
    at the end of my loop I attribute $myCONTENT to the_content() and I appear like this:

    global $ post;
    $post-> post_content = $MyContent;
    setup_postdata($post);
    remove_filter('the_content', 'wpautop');
    the_content();
    wp_link_pages();

    This works well but I do not know what it is worth in terms of performance.
    Your solution looks more flexible. I would try in the coming days.
    thank you very much

  • I think I’m trying to accomplish the exact same thing as @pixaro, but I’ve been spinning my wheels for hours and getting nowhere.

    To be clear, I’m trying to split each flexible content section into its own page, as if I were using <!--nextpage--> in the content.

    Here’s a screenshot of my relevant layouts. You can see I’m attempting to use a layout called “Page Break” containing a true/false field called “Break Here” to create the breaks.

    Here’s the simple, working loop I’m using to get the “Section Title” and “Section Text” into the page.

    <?php while(has_sub_field("content")): ?>
      <?php if(get_row_layout() == "section_content"):  ?>
        <h2><?php the_sub_field("section_title"); ?></h2>
        <?php the_sub_field("section_text"); ?>
      <?php endif; ?>
    <?php endwhile; ?>

    Beyond this, I’m lost. I’ve tried a number of things, including creating a counter using this information, but I could never get it to work.

    Could anyone possibly share a more complete solution?

  • Here’s one other solution I tried, but it did not work, it just spits out <p><!--nextpage--></p>:

    <?php while(has_sub_field("content")): ?>
      <?php if(get_row_layout() == "section_content"):  ?>
        <h2><?php the_sub_field("section_title"); ?></h2>
        
        <?php 
          $section_text = the_sub_field("section_text");
          $section_content = $section_text . '<!--nextpage-->';
          $content = apply_filters('acf_the_content', $section_content);
          echo $content;
        ?>
    
      <?php endif; ?>
    <?php endwhile; ?>
    • pixaro

    • December 3, 2013 at 6:29 pm

    I’ll try to explain but I’m not an expert in php. I do not know if I did it right but it works. I ended up using the elliot’s solution and it works well.

    1. i create a field “break”;

    2. Before the loop “while” i get the page create a counter variable which starts at 1 and gets increased each time the “break” layout is used like elliot says :

    <?php  $paged = (get_query_var('page')) ? get_query_var('page') : 1; 
            $MyContent = " " ;//variable for <!--nextpage-->
            $count =1; ?>

    3. Then the loop

    <?php while(has_sub_field("content")): ?>
    
      <?php if(get_row_layout() == "break"):  ?>
        <?php $MyContent .= "<!--nextpage-->\n";          
              $count++; ?>
      <?php endif; ?>
    
      <?php if(get_row_layout() == "section_content"):  ?>
          <?php if ($count != $paged){
    	continue; //ignore the current loop’s layout. 
          }?>
        //your content
    <?php endif; ?>
    <?php endwhile; ?>
    ///after the loop put pagination
    <?php 	global $post;
            $post->post_content = $MyContent;
    	setup_postdata($post);
    
    	 wp_link_pages(); 
    ?>

    Sorry for my english, i hope that help you

    • Elliot

    • December 4, 2013 at 10:10 am

    Hi guys

    I have written some repeater field pagination code in this thread:
    http://support.advancedcustomfields.com/forums/topic/advanced-custom-repeater-field-page-navigation/

    Hopfully, this will help you build your own.

    Cheers
    E

  • <?php
    $args = array(‘post_type’ => ‘fhb_news’, ‘posts_per_page’ => 3);
    $loop = new WP_Query($args);
    while ($loop->have_posts()) : $loop->the_post();
    ?>
    <div class=”modal-content modal-content-styling”>
    <div class=”datum”>
    <?php the_date(‘scheduled_date’); ?>
    </div><h3><?php the_title(); ?></h3>
    <div class=”Anreissertext”><?php the_content(); ?></div>
    <div class=”weitereinfos-startseite”>
    <div id=”myModal-<?php the_id(); ?>” class=”modal fade out” role=”dialog” style=”display: none;” aria-hidden=”true”>
    <div class=”modal-dialog modal-dialog-styling”>
    <!– Modal content–>
    <div class=”modal-content modal-content-styling”>
    <div class=”modal-header modal-header-styling”>
    <div class=”col-12″>
    <div class=”lightbox-caption”>
    News-Details
    <button type=”button” class=”close lightbox-close” data-dismiss=”modal” aria-label=”Close”>
    <span aria-hidden=”true”>×</span>
    </button>
    </div>
    </div>
    </div>
    <div class=”modal-body modal-body-styling”>
    <div class=”row”>
    <div class=”col-12 col-md-7″>
    <div style=”margin-left:2%;” class=”h2-in-lightbox”>
    <?php the_field(‘news_detail_title’); ?>
    </div>

    <div style=”margin-left:2%;” class=”text-in-lightbox”>
    <?php the_field(‘news_detail_beschreibung’); ?>
    </div>
    </div>
    <!–Side box Title–>
    <div class=”col-12 col-md-5″>
    <div class=”col-12″>
    <?php if (get_field(‘sideboxtitle’) && get_field(‘news_download’)) { ?>
    <div class=”Ort-Kasten-unten”>
    <div class=”h1-Kasten”><?php the_field(‘sideboxtitle’); ?></div>

    <?php $file = get_field(‘news_download’); ?>
    “>Marktbericht (PDF)
    “>
    </div>
    <?php } ?>
    <!–_____Side img__________–>
    <?php
    $image_url = get_field(‘sideimg’);
    ?>
    <?php if (isset($image_url)) { ?>
    <div class=”container”>
    <div class=”row”>
    “>
    </div>
    </div>
    <?php } ?>

    Ihave this code would like to pagination i have tried all my efferot can any one help me

  • <?php
    $args = array(‘post_type’ => ‘fhb_news’, ‘posts_per_page’ => 3);
    $loop = new WP_Query($args);
    while ($loop->have_posts()) : $loop->the_post();
    ?>
    <div class=”modal-content modal-content-styling”>
    <div class=”datum”>
    <?php the_date(‘scheduled_date’); ?>
    </div><h3><?php the_title(); ?></h3>
    <div class=”Anreissertext”><?php the_content(); ?></div>
    <div class=”weitereinfos-startseite”>
    <div id=”myModal-<?php the_id(); ?>” class=”modal fade out” role=”dialog” style=”display: none;” aria-hidden=”true”>
    <div class=”modal-dialog modal-dialog-styling”>
    <!– Modal content–>
    <div class=”modal-content modal-content-styling”>
    <div class=”modal-header modal-header-styling”>
    <div class=”col-12″>
    <div class=”lightbox-caption”>
    News-Details
    <button type=”button” class=”close lightbox-close” data-dismiss=”modal” aria-label=”Close”>
    <span aria-hidden=”true”>×</span>
    </button>
    </div>
    </div>
    </div>
    <div class=”modal-body modal-body-styling”>
    <div class=”row”>
    <div class=”col-12 col-md-7″>
    <div style=”margin-left:2%;” class=”h2-in-lightbox”>
    <?php the_field(‘news_detail_title’); ?>
    </div>

    <div style=”margin-left:2%;” class=”text-in-lightbox”>
    <?php the_field(‘news_detail_beschreibung’); ?>
    </div>
    </div>
    <!–Side box Title–>
    <div class=”col-12 col-md-5″>
    <div class=”col-12″>
    <?php if (get_field(‘sideboxtitle’) && get_field(‘news_download’)) { ?>
    <div class=”Ort-Kasten-unten”>
    <div class=”h1-Kasten”><?php the_field(‘sideboxtitle’); ?></div>

    <?php $file = get_field(‘news_download’); ?>
    “>Marktbericht (PDF)
    “>
    </div>
    <?php } ?>
    <!–_____Side img__________–>
    <?php
    $image_url = get_field(‘sideimg’);
    ?>
    <?php if (isset($image_url)) { ?>
    <div class=”container”>
    <div class=”row”>
    “>
    </div>
    </div>
    <?php } ?>

    Ihave this code would like to pagination i have tried all my efferot can any one help me

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.