function test_separator_output()
 {
     $output = P2P_List_Renderer::render(self::$list, array('separator' => __FUNCTION__, 'echo' => false));
     $this->assertNotEmpty($output);
     // 'separator' should appear n-1 times in the output
     $this->assertEquals(count(self::$list->items) - 1, self::count_occurences($output, __FUNCTION__));
     // 'before_list' and 'after_list' should be ignored
     $this->assertStringStartsNotWith('<ul>', $output);
     $this->assertStringEndsNotWith('</ul>', $output);
 }
Exemple #2
0
 function widget($args, $instance)
 {
     $instance = array_merge($this->defaults, $instance);
     $output = P2P_List_Renderer::query_and_render(array('ctype' => $instance['ctype'], 'method' => 'related' == $instance['listing'] ? 'get_related' : 'get_connected', 'item' => get_queried_object(), 'mode' => 'ul', 'context' => 'widget'));
     if (!$output) {
         return;
     }
     $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     echo $args['before_widget'];
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     echo $output;
     echo $args['after_widget'];
 }
 private static function get_list($attr, $method)
 {
     global $post;
     $attr = shortcode_atts(array('type' => '', 'mode' => 'ul'), $attr);
     return P2P_List_Renderer::query_and_render(array('ctype' => $attr['type'], 'method' => $method, 'item' => $post, 'mode' => $attr['mode'], 'context' => 'shortcode'));
 }
Exemple #4
0
/**
 * List some items.
 *
 * @param object|array A P2P_List instance, a WP_Query instance, or a list of post objects
 * @param array $args (optional)
 */
function p2p_list_posts($posts, $args = array())
{
    if (is_a($posts, 'P2P_List')) {
        $list = $posts;
    } else {
        if (is_a($posts, 'WP_Query')) {
            $posts = $posts->posts;
        }
        $list = new P2P_List($posts, 'P2P_Item_Post');
    }
    return P2P_List_Renderer::render($list, $args);
}