Forum

Thread tagged as: Problem

Start not working on custom_cotent

Hi Guys,

I have the following code;

            $page = intval($_GET["page"]);
            if ($page < 2) { $count = 8; } else { $count = 9; }

            perch_content_custom('Stories', [
                'template'              => 'stories/_combined',
                'sort'                  => 'date',
                'sort-order'            => 'DESC',
                'count'                 => $count,
                'paginate'              => true,
                'page-links'            => true,
                'page-link-style'       => all,
                'start'                 => 9
            ]);

However the start value doesn't appear to be working no matter what I enter.
If I remove the paginate option then it works.

Any ideas?

Thanks, Terry

Terry Upton

Terry Upton 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't both set the start position and ask pagination to do it. It's one or the other.

Ok. The problem I actually facing is this, if you have any ideas? So my templates are as follows;

_featured

<div class="box--wavey // box--<perch:categories id="age_group"><perch:category id="catClass" format="LC" /></perch:categories> //// teaser //  teaser--story-featured">
    <div class="container  // equal-height">
        <div class="teaser--story-featured__img">
            <a href="/stories/<perch:content id="story_slug" type="slug" />/">
            <perch:if exists="story_image">
                <img
                    src="/assets/img/story-no-image.svg"
                    data-src="<perch:content id="story_image" type="image" label="Image" order="3" width="200" height="200" crop="true" bucket="stories" />"
                    data-srcset="<perch:content id="story_image" type="image" width="200" height="200" crop="true" bucket="stories" density="1" /> 1x, <perch:content id="story_image" type="image" width="200" height="200" crop="true" bucket="stories" density="2" /> 2x"

                    alt="<perch:content id="name" type="text" label="Childs Name" required="true" title="true" order="1" />'s Story"
                    class="img-circle // img-circle--border-medium // lazyload"
                />
            <perch:else />
            <img src="/assets/img/story-no-image.svg" width="200" height="200" alt="No Image Available" class="img-circle // img-circle--border-medium">
            </perch:if>

            </a>
        </div>

        <div class="teaser--story-featured__content">
            <h2 class="teaser__title"><perch:content id="name" type="text" />’s Story</h2>
            <p class="date"><perch:content id="date" type="date" format="%B %G" /></p>
            <p><perch:content id="excerpt" type="textarea" label="Excerpt" help="Enter the short description for the story" size="s" /></p>

        </div>

        <ul class="nav--cats">
            <perch:categories id="diagnosis" label="Diagnosis" set="diagnosis" required="true" display-as="lists">
            <li><a href="/stories/<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>
            </perch:categories>
            </li>
            <perch:categories id="age_group" label="Age Group" set="age-group" required="true" display-as="lists">
            <li><a href="/stories/<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>
            </perch:categories>
        </ul>
    </div>

    <div class="container">
        <div class="teaser__btn">
            <a href="/stories/<perch:content id="story_slug" type="slug" />/" class="btn">Read Story</a>
        </div>
    </div>
</div>

__teaser 

<div class="box--wavey // box--<perch:categories id="age_group"><perch:category id="catClass" format="LC" /></perch:categories> //// teaser // teaser--story">
    <div class="container  // equal-height">
        <div class="teaser--story__img">
            <a href="/stories/<perch:content id="story_slug" type="slug" />/">
            <perch:if exists="story_image">
                <img
                    src="/assets/img/story-no-image.svg"
                    data-src="<perch:content id="story_image" type="image" label="Image" order="3" width="140" height="140" crop="true" bucket="stories" />"
                    data-srcset="<perch:content id="story_image" type="image" width="140" height="140" crop="true" bucket="stories" density="1" /> 1x, <perch:content id="story_image" type="image" width="140" height="140" crop="true" bucket="stories" density="2" /> 2x"

                    alt="<perch:content id="name" type="text" label="Childs Name" required="true" title="true" order="1" />'s Story"
                    class="img-circle // img-circle--border-medium // lazyload"
                />
            <perch:else />
            <img src="/assets/img/story-no-image.svg" width="140" height="140" alt="No Image Available" class="img-circle // img-circle--border-medium">
            </perch:if>

            </a>
        </div>

        <div class="teaser--story__content">
            <h2 class="teaser__title"><perch:content id="name" type="text" />’s Story</h2>
            <p class="date"><perch:content id="date" type="date" format="%B %G" /></p>
        </div>

        <p><perch:content id="excerpt" type="textarea" label="Excerpt" help="Enter the short description for the story" size="s" /></p>

        <ul class="nav--cats">
            <perch:categories id="diagnosis" label="Diagnosis" set="diagnosis" required="true" display-as="lists">
            <li><a href="/stories/<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>
            </perch:categories>
            </li>
            <perch:categories id="age_group" label="Age Group" set="age-group" required="true" display-as="lists">
            <li><a href="/stories/<perch:category id="catPath" />"><perch:category id="catTitle" /></a></li>
            </perch:categories>
        </ul>
    </div>

    <div class="container">
        <div class="teaser__btn">
            <a href="/stories/<perch:content id="story_slug" type="slug" />/" class="btn">Read Story</a>
        </div>
    </div>
</div>

<perch:after>
    <perch:if exists="not_first_page">
        <perch:if exists="paging">
            <nav id="nav" role="navigation" class="pagination">
                <perch:template path="pagination/default.html" rescope="parent" />
            </nav>
        </perch:if>
    </perch:if>
</perch:after>

<!--*
<perch:noresults>
    <h2>☹ Sorry - There are no stories</h2>
    <p>We are very sorry, but it appears that there are no stories currently available for this section.<br />
    Please try and navigate from the main <a href="/stories/">Super Stories</a> page. If you think you have reached this page in error, please feel free to <a href="/contact/">contact us</a>.</p>
</perch:noresults>
*-->


__combined
<perch:if exists="not_first_page">
    <perch:before>
    <div class="container // teaser-page">
    </perch:before>
        <perch:template path="content/stories/_teaser.html" />
    <perch:after>
    </div>
    </perch:after>

<perch:else />

    <perch:before>
    <div class="container // teaser-page">
    </perch:before>

    <perch:if id="perch_item_index" value="3" match="lt">
    <!--* DO THE FEATURED BOXES *-->
    <perch:template path="content/stories/_featured.html" />

    <!--* BIT OF TRICK TO CHECK IF THE THIRD ITEM THEN TO DO THE CONTAINER *-->
    <perch:if id="perch_item_index" value="2" match="eq">
    </div>
    <div class="container">
    </perch:if>

    <perch:else />

    <!--* NOW DO THE TEASER BOXES *-->
    <perch:template path="content/stories/_teaser.html" />
    </perch:if>


    <perch:after>
    </div>
    </perch:after>


    <perch:after>
        <perch:if exists="paging">
            <div class="pagination">
                <perch:template path="pagination/default.html" rescope="parent" />
            </div>
        </perch:if>
    </perch:after>

</perch:if>

What I am doing is setting the count to 8 on the first page as the first two items on he first page are bigger (like featured boxes) and span half and half, the other boxes then span in thirds. So on the first page I have a count of 8 to display 8 items to accommodate for the bigger feature boxes.

But on pages 2 and upwards I set the count to 9 as I want it to just display the _teaser template in columns of 3.

The problem I am facing is it is missing off item 9. So page 1 displays 1-8
But page 2 the first item is item number 10.

I am assuming because on page 2 it thinks the previous count has been 9 so therefore starts at position 10.

Any ideas on how I can resolve this?

Thanks.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Keep the count the same for all pages.

In the template, if it's page 1 don't output the first 2 items.

Sorry Drew, not sure I follow? I don't quote understand how I can show 8 items on page one and 9 on the other pages? Even if I exclude the first two. I have been playing around and not got anywhere.

Would you be able to elaborate on what you mean / the approach?

Thanks,

Just wonder if the URL might be useful so you can visually see what I am trying to do;
https://www.supershoes.org.uk/stories/

Thanks,

Drew McLellan

Drew McLellan 2638 points
Perch Support

If it's page 1, test to see if you're on index 1 or 2. If you are, don't output the item.

If that's not working, show me your code and I can help debug it.

I managed to get around it with a little messy code - breaking the code out into separate blocks, pulling in the last article in the previous pagination and using the start parameter, then ignoring the last item. So a little convoluted and messy.

        <?php

            $page = intval($_GET["page"]);
            $start = ($page-1)*9;

            if ($page < 2) {
                perch_content_custom('Stories', [
                    'template'              => 'stories/_featured',
                    'sort'                  => 'date',
                    'sort-order'            => 'DESC',
                    'count'                 => 2,
                ]);

                perch_content_custom('Stories', [
                    'template'              => 'stories/_first_page',
                    'sort'                  => 'date',
                    'sort-order'            => 'DESC',
                    'count'                 => 8,
                    'paginate'              => true,
                    'page-links'            => true,
                    'page-link-style'       => all,
                ]);

            } else {
                echo '<div class="container // teaser-page">';

                perch_content_custom('Stories', [
                    'template'              => 'stories/_teaser',
                    'sort'                  => 'date',
                    'sort-order'            => 'DESC',
                    'count'                 => 1,
                    'start'                 => $start
                ]);

                perch_content_custom('Stories', [
                    'template'              => 'stories/_combined',
                    'sort'                  => 'date',
                    'sort-order'            => 'DESC',
                    'count'                 => 9,
                    'paginate'              => true,
                    'page-links'            => true,
                    'page-link-style'       => all,
                ]);

                echo '</div>';
            }

        ?>
<perch:if exists="not_last_page">
    <perch:if not-exists="perch_item_last">
        <perch:template path="content/stories/_teaser.html" />
    </perch:if>
<perch:else />
        <perch:template path="content/stories/_teaser.html" />
</perch:if>

<perch:after>
    <perch:if exists="paging">
        <nav id="nav" role="navigation" class="pagination">
            <perch:template path="pagination/default.html" rescope="parent" />
        </nav>
    </perch:if>
</perch:after>

The site went live officially today so I really had to sort something.
I plan to come back and readdress this and will look at your suggestion Drew.

Thanks.