Forum

Thread tagged as: Question, MailChimp

Mailchimp App: limiting the number of campaigns listed on the archive page

Hello! I have the Mailchimp app working, and if I just use the example files provided, it outputs a list of all the campaigns I've sent on the /campaigns.php page just fine.

What I would like to do is limit the number of campaigns shown, say just the last 3 or something like that. It would be a similar thing to what is output by the perch_blog_recent_posts(3); tag.

I thought maybe I could use the 'max' attribute in a repeater to limit the output, but I am really not sure I'm understanding the way the repeater works at all and if it's even appropriate in this case. Am I on the right track or wrong track or is there a better/easier way?

My list.html template (this outputs just the before/after <ul> elements, but nothing else):

<perch:before>
    <ul>
</perch:before>

<perch:repeater id="recentcampaigns" label="Recent Campaigns" max="3">

    <li>
        <h2>
            <a href="<perch:mailchimp id="campaignURL" type="text" />">
                <perch:mailchimp id="campaignSubject" type="text" />
            </a>
        </h2>
        <p><perch:mailchimp id="campaignSendTime" type="date" format="d F Y" /></p>
    </li>

</perch:repeater>

<perch:after>
    </ul>
</perch:after>

My campaigns.php file (which is the included example file, but with my header information)

<?php include('../perch/runtime.php'); ?>
<?php perch_layout('global.head'); ?>

<body class="newsletter">

<?php perch_layout('global.banner'); ?>

    <div class="with-margin cols2-nav-right">

        <div class="primary-content">
           <?php perch_mailchimp_campaigns(); ?>
        </div>

        <nav class="sidebar">

        </nav>
    </div>
    <footer class="layout-footer">
        <div class="with-margin">
            <small>Copyright © <?php echo date('Y'); ?></small>
        </div>
    </footer>
    <?php perch_get_javascript(); ?>
</body>
</html>
Laura Fisher

Laura Fisher 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to use the count option

perch_mailchimp_campaigns([
    'count' => 3
]);

Ah ha ha! I was just coming over here to write that I had discovered that I could do it that way! Thank you for confirming!

<?php perch_mailchimp_campaigns(array(
             'count'      => 3,
             'template'   => 'campaigns/list.html'
              )); ?>