[Plugin: Posts 2 Posts] Looping the loop function help
-
Hello! ??
I’ve succesfully applied the “less efficient” code listed on page Looping-The-Loop.
But i can’t get to work the second one, the efficient code!
I have defined in functions this code:
function my_connection_types() { // Make sure the Posts 2 Posts plugin is active. if ( !function_exists( 'p2p_register_connection_type' ) ) return; // Keep a reference to the connection type; we'll need it later global $my_connection_type; $my_connection_type = p2p_register_connection_type( array( 'id' => 'posts2pages', 'from' => 'custom_post_type_1', 'to' => 'custom_post_type_2' ) ); } add_action( 'init', 'my_connection_types', 100 );
Then I have a page where I already have a loop and where i’ve placed the first “less efficient” code:
<?php /* Template Name: Name */ ?> <?php get_header(); ?> <div> <h5>Heading name</h5> <ul> <?php $args = array('post_type'=> 'custom_post_type_1', 'posts_per_page'=> -1); ?> <?php query_posts($args); ?> <?php if(have_posts()) : while(have_posts()) : the_post(); ?> <li> <a href="<?php the_permalink(); ?>"> <?php the_post_thumbnail('label-thumb'); ?> </a> <div> <h2> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> </h2> <?php // Find connected pages $connected = $my_connection_type->get_connected( $post->ID ); // Display connected pages p2p_list_posts( $connected ); ?> </div> </li> <?php endwhile; endif; wp_reset_query(); ?> </ul> </div> <?php get_footer(); ?>
This page template show the connected pages, but out of be less efficient, it wraps the connected pages into an extra ‘ul’ and each page link into a ‘li’ with his relative anchor ‘a’.
Probably i haven’t yet a great php knowledge but i would to display the connected pages only as anchor ‘a’ without wrapping them into a ‘li’ list.
Then i’ve tried to put into this template page the second “more efficient” code but i have an error showing into the page:
Fatal error: Call to a member function each_connected() on a non-object in address-bla-bla.php on line 25
I would be glad if someone can help me!
Thank you!
- The topic ‘[Plugin: Posts 2 Posts] Looping the loop function help’ is closed to new replies.