开发者

PHP - limiting the output of a plugin

开发者 https://www.devze.com 2023-03-25 15:38 出处:网络
I\'m using a plugin titled \"WP Recent Links\" which I first le开发者_开发知识库arned about via Eric Meyer\'s site. Eric uses to display a Link Log within his site and I\'m doing the same on my test s

I'm using a plugin titled "WP Recent Links" which I first le开发者_开发知识库arned about via Eric Meyer's site. Eric uses to display a Link Log within his site and I'm doing the same on my test site - http://matala.jorgeledesma.net/ but I'm running into a little situation and that is that I don't know how to limit the output either on the sidebar or the actual page - http://matala.jorgeledesma.net/recent-links/

My goal is to have it echo only the first 5 entries on the sidebar and for the recent-links page only echo the current month. The code below displays the sidebar properly

<?php if (!is_page('48')) { ?>
                    <aside id="meta" class="widget">
                    <h1 class="widget-title">Link Log</h1>
                    <?php if ($links = rp_recentlinks_home()) {  ?>
<ul>
    <?php foreach ($links as $link) { ?>

   <b><li><a href="<?php echo $link->link_url; ?>"><?php echo wptexturize($link->link_text); ?></a></b>
    <?php if ('' != $link->link_caption) { ?>&#8594;
    <?php echo wptexturize(convert_smilies($link->link_caption)); ?><?php } ?>
    <a href="<?php echo $link->link_permalink; ?>"></a></li>

    <?php } ?>

</ul>
<?php } ?>
                </aside>
                <?php } ?>

and this code display the actual recent-links page

    <h1 class="page-title"><?php rp_recentlinks_archive_header(); ?></h1>
                    </header>

<div class="entry-content">
    <?php $links = rp_recentlinks_archive_page(); ?>
</div>
    <?php if ($links) {  ?>
    <ul>
        <?php foreach ($links as $link) { ?>

            <p id="rlink-<?php echo $link->ID; ?>"><a href="<?php echo $link->link_url; ?>"><?php echo wptexturize($link->link_text); ?></a>
            <?php if ('' != $link->link_caption) { ?>&#8594;
            <?php echo wptexturize(convert_smilies($link->link_caption)); ?><?php } ?>
            <a href="<?php echo $link->link_permalink; ?>" class="permalink"></a></p>



        <?php } ?>
    </ul>
    <?php } ?>

I tried putting the following code in the body.

$list = array_slice($input, 0, 5); // $list now only having first 5 item.

But I don't know how to apply it, if that's the command at all. So perhaps, someone can guide in the right direction. Thanks in advance, Jorge.


Looks like all you have to add is this before you pass $links to the foreach loop:

$links = array_slice($links,0,5);
0

精彩评论

暂无评论...
验证码 换一张
取 消