function widget($args, $instance) { if (!is_singular()) { return; } $instance = array_merge($this->defaults, $instance); $post_id = get_queried_object_id(); $ctype = p2p_type($instance['ctype']); if (!$ctype) { return; } $directed = $ctype->find_direction($post_id); if (!$directed) { return; } if ('related' == $instance['listing']) { $connected = $ctype->get_related($post_id); $title = sprintf(__('Related %s', P2P_TEXTDOMAIN), $directed->get_current('side')->get_title()); } else { $connected = $directed->get_connected($post_id); $title = $directed->get_current('title'); } if (!$connected->have_posts()) { return; } $title = apply_filters('widget_title', $title, $instance, $this->id_base); extract($args); echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } p2p_list_posts($connected); echo $after_widget; }
/** * Session Loop * */ function sc_session_loop($args = array()) { $loop = new WP_Query($args); if ($loop->have_posts()) { while ($loop->have_posts()) { $loop->the_post(); global $post; echo '<div class="session">'; echo '<div class="left">'; echo '<h3>' . esc_attr(get_post_meta($post->ID, 'sc_session_time', true)) . '</h3>'; echo wpautop(get_post_meta($post->ID, 'sc_session_location', true)); echo '</div>'; echo '<div class="right">'; echo '<h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>'; $content = get_the_content(); if (function_exists('p2p_list_posts')) { $connected = p2p_type('sessions_to_speakers')->get_connected($post->ID); p2p_list_posts($connected, array('before_list' => '<p>by ', 'after_list' => '</p>', 'before_item' => '', 'after_item' => ' ')); } echo $content; echo '</div>'; echo '</div>'; } } wp_reset_query(); }
<?php get_header(); the_post(); ?> <div class="row"> <?php get_sidebar('conferences'); ?> <div class="content"> <?php get_template_part('page', 'article'); ?> <?php $talks = p2p_type('talk_to_schedule')->get_connected(get_the_id()); ?> <?php p2p_list_posts($talks, array('template' => 'single-talk-embed.php', 'before_list' => '', 'after_list' => '', 'before_item' => '', 'after_item' => '')); ?> </div> </div> <?php get_footer();
function test_p2p_list_posts_separator() { $actor = $this->generate_post('actor'); $movie = $this->generate_post('movie'); $ctype = p2p_type('actor_to_movie'); $ctype->connect($actor, $movie); $connected = $ctype->get_connected($movie); p2p_list_posts($connected, array('separator' => ', ', 'echo' => false)); }
/** * Displays speakers for a given talk, easy way * * @param $post_id * @param array $args * @return null */ function sudweb_list_speakers($post_id, array $args = array()) { if (!function_exists('p2p_list_posts')) { return null; } if (array_search('inherit', $args) === false) { $args = array_merge(array('before_list' => '<span class="post-speaker">', 'after_list' => '</span>', 'before_item' => '', 'after_item' => ' '), $args); } $speakers = p2p_type('talk_to_speaker')->get_connected($post_id); if ($speakers->post_count) { p2p_list_posts($speakers, $args); } }