0

Alright let me explain. I am using a function to get all Wordpress Tags and display them. That is fine.:

What I'm trying to do is display these tags first in one place where space is limited and then continuing to display them else where without conflicts.

$tagargs = array(
        'number' => 60,
        'orderby' => 'count',
        'order' => 'DESC'
        );

$sunnytags =  get_tags( $tagargs );
foreach ($sunnytags as $tag) { 
$string .= '<a class="tag2" href="'. get_tag_link($tag->term_id) .'">'. $tag->name . '</a>';
} 
return $string;

That's the code. The place its in can only display 15 tags and then I'd have to continue the display somewhere else, which means running the same code but filtering it against the first one.

I have explored the php vocabulary but Havent got it working yet...

I thought about using an array filter for the new function that would filter out the first 15 tags and go on from there.

array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )

What are your thoughts? can anyone help me=

1 Answer 1

2

How about using a standard for loop instead:

$sunnytags = get_tags ($tagargs);
$count = count ($sunnytags);
for ($i = 0; $i < ($count < 15 ? $count : 15); $i++) {
    $string .= '<a class="tag2" href="'. get_tag_link ($sunnytags[$i]->term_id) .'">'. $sunnytags[$i]->name . '</a>';
}

And then later, whether you re-run the query or (better still) save $sunnytags for later use, you can get the rest of the elements like this:

for ($i = 15; $i < $count; $i++) {
    // Process the rest of them here as $sunnytags[$i]
}
1
  • Coding maestro! Works as intended. Infinitely grateful for the quick and thorough response. The internet salutes you!
    – Sanel
    Jan 4, 2017 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.