Vote count:
0
How can I alter "CODE A" below to "repeat the loop" or "rewind the loop" or "create infinite loop" ?
I display my posts in a 3 column layout. And I am using Birgire's Injector plugin to inject a post from a specific category (such as a "sponsored" category).
I upload the plugin and I put "CODE A" (see below) in functions.php
It is a great plugin, but I'd like for the plugin to repeat the loop. For example, if I have 2 posts in the "sponsored" category, then page 1 will display the first sponsored post,
and page 2 will display the second sponsored post,
but page 3 and beyond will display nothing, so the layout will will show empty space.
I want the plugin to repeat the loop.
.
My Problem: Need loop to repeat otherwise empty space on page 3
.
X represents my posts
O represents sponsored posts injected by the plugin
Page 1 Page 2 Page 3
X X X X X X X X X
X X X X X X X X X
X O X X O X X X
.
CODE A: Code below is to be used with Birgire's Injector plugin
add_action( 'wp', 'my_sponsor_injections' );
function my_sponsor_injections()
{
if( ! class_exists( 'SponsorPostsInjector' ) ) return;
// We want the sponsor posts injections on everything except the home page:
if( is_search() ) return;
// Setup the injection:
$injector = new SponsorPostsInjector(
array(
'items_before_each_inject' => 5,
'items_per_inject' => 1,
'template_part' => 'content-sponsor',
)
);
// Setup the injection query:
$injector->query(
array(
'category_name' => 'sponsor'
)
);
// Inject:
$injector->inject();
}
Repeat the loop for wordpress
Aucun commentaire:
Enregistrer un commentaire