Skip to content

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.

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=' ); ?>

Clone this wiki locally