-
Notifications
You must be signed in to change notification settings - Fork 262
Using p2p_list_posts()
scribu edited this page Oct 27, 2011
·
8 revisions
p2p_list_posts()
is an utility function that, as it's name suggests, outputs a list of posts.
It accepts either a WP_Query instance or a plain array of posts.
Here's how we could rewrite the Basic usage example:
<?php $connected = p2p_type( 'posts_to_pages' )->get_connected( get_queried_object_id() ); ?>
<?php p2p_list_posts( $connected, 'before_list=<h3>Related posts</h3><ul>' ); ?>
To use an ordered list instead of an unordered list:
<?php p2p_list_posts( $connected, 'before_list=<h3>Related posts</h3><ol>&after_list=</ol>' ); ?>
To output links directly, without wrapping them in an unordered list, use:
<?php p2p_list_posts( $connected, 'before_list=&after_list=&before_item= &after_item=' ); ?>
You can also pass an array instead of a long string:
<?php
p2p_list_posts( $connected, array(
'before_list' => '<h3>Related posts</h3><ol>',
'after_list' => '</ol>',
'before_item' => '<li>',
'after_item' => '</li>',
) );
?>