• Second question (sorry for that),
    it’s hard for my little head to understant clearly how your plugin works (I’m a little lost with from and to). OK, I managed to show related posts FROM (default behaviour).
    I want now tho show posts TO. I look at Wiki the code… and I cannot understand. It’s exactly the same code for the two so I’ve got the same output. I did use Winmerge to get sure I was not dreaming. The SAME code πŸ™‚

    http://ww.wp.xz.cn/extend/plugins/posts-to-posts/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author scribu

    (@scribu)

    I need to know:

    * what the call to p2p_register_connection_type() looks like
    * what the code you’re having trouble with looks like
    * the template file in which said code is added

    Even if it’s the same code, the value of get_queried_object_id() is different.

    Thread Starter Li-An

    (@li-an)

    Thank you for quick answer.
    I put this:

    <?php
    function my_connection_types() {
    	// Make sure the Posts 2 Posts plugin is active.
    	if ( !function_exists( 'p2p_register_connection_type' ) )
    		return;
    
    	p2p_register_connection_type( array(
    		'id' => 'page_un',
    		'from' => 'webcomic',
    		'to' => 'webcomic',
    		'sortable' => 'any',
    
    		)
    		);
    }
    add_action( 'init', 'my_connection_types', 100 );
    ?>

    I added the code in a single-webcomic.php (custom post).

    Maybe I have not understand how the plugin works. I try to explain what I try to do (sorry for my bad English).
    I want to create a webcomics navigation. Each comics page is a custom post (named webcomic). As there will be a lot of short stories, I wanted to use your plugin to link every posts of each story. To manage the stories, I thought I had to make the first post of the story special.
    An example: a story with page 1, page 2 and page 3. To list all the pages related to one page, I used the FROM feature and add the two other pages. No problem, the code shows the related pages.
    Now, I need a link to the first page of the story (“go to first page”). I tried to link TO page 2 and 3 to page 1 but I don’t know to get the link to page 1. Maybe I’m completely wrong.

    Plugin Author scribu

    (@scribu)

    Interesting approach. I would have created an additional “serie” post type that would be connected to all the webcomics.

    Anyway, this should work:

    $query = new WP_Query( array(
      'p2p_type' => 'page_un',
      'post_type' => 'webcomic',
      'connected_to' => get_queried_object_id(),
    ) );
    
    $first_comic = $query->posts[0];

    The 'connected_to' part is important.

    Thread Starter Li-An

    (@li-an)

    Interesting approach. I would have created an additional “serie” post type that would be connected to all the webcomics.

    Could you explain more ? For the moment, I decided to create a custom taxonomy with one tag: “first page”. Every first page will get this tag so I can list all stories, showing only the first page πŸ™‚ (and maybe a custom field with the title of the story but I did not find how to show this title in the other pages. I tink I will have to give the same custom field to all posts).

    Thank you for your code but I did not manage to use the $first_comic to get the link to first post. Could you explain ? (and sorry for such dumb questions).

    Plugin Author scribu

    (@scribu)

    A ‘serie’ post would just be a container for ‘webcomic’ posts.

    The connection type would look like this:

    p2p_register_connection_type( array(
      'id' => 'page_un',
      'from' => 'serie',
      'to' => 'webcomic',
      'sortable' => true
    ) );

    You can also set ‘cardinality’ => ‘one-to-many’ if you want a webcomic to only belong to a single serie.

    You should just be able to follow the explanations on the wiki:

    https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage

    Thread Starter Li-An

    (@li-an)

    I will study this. It’s very nice for you to make such suggestions as I am searching for good advice.

    And for the $first_comic = $query->posts[0]; code and how to retrieve the first page link ?

    Plugin Author scribu

    (@scribu)

    echo get_permalink( $first_comic );

    But if you’re going with the ‘serie’ post type, it will be different.

    Thread Starter Li-An

    (@li-an)

    Thank you. It works. Now I will take a look at the series concept and I’m afraid I will need your help πŸ™‚

    Thread Starter Li-An

    (@li-an)

    OK, here I am again. I have created my “stories” post type and register the connection to webcomics page with ‘cardinality’ => ‘one-to-many’.
    Now, I have to create in each webcomics page a link to “previous story” and “next story”. And I have no idea how to get this πŸ™‚
    And a link to the story.
    Sorry for this questions but I did not find any information on the wiki or maybe I did not look at the good place.

    Plugin Author scribu

    (@scribu)

    In your single-webcomic.php file:

    https://gist.github.com/20d28d3066d61eb46852

    Thread Starter Li-An

    (@li-an)

    Thank you again πŸ™‚ I plan to make a complete tutorial about this webcomics concept when I will achieve it.

    Thread Starter Li-An

    (@li-an)

    OK…
    I’ve got this

    p2p_register_connection_type( array(
    		'id' => 'histoire',
    		'from' => 'stories',
    		'to' => 'webcomic',
    		'sortable' => 'true',
    		'cardinality' => 'one-to-many',
    		'title' => array( 'from' => 'ReliΓ©s', 'to' => 'Histoire' ),
    		)
    		);

    and

    <?php
    // Collect the relevant ids
    
    $comic_id = get_queried_object_id();
    
    $story_id = p2p_type( 'histoire' )->get_connected( $comic_id )->posts[0]->ID;
    
    $prev = p2p_type( 'histoire' )->get_prev( $comic_id, $story_id );
    
    $next = p2p_type( 'histoire' )->get_next( $comic_id, $story_id );
    
    // Display what we found
    
      echo get_permalink( $prev );
    
    echo get_permalink( $story_id );
    
      echo get_permalink( $next );
      ?>

    and an error about get_prev and get_next

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, class ‘P2P_Directed_Connection_Type’ does not have a method ‘get_prev’ in E:\xampp\htdocs\wordpress\wp-content\plugins\posts-to-posts\core\type.php on line 86

    The echo $prev and $next give me the URL of the actual post. $story_id is OK.

    And I forget to say I need the link to the first post of the webcomics in previous and next story πŸ™‚

    Plugin Author scribu

    (@scribu)

    Right, it’s get_previous, not get_prev.

    Thread Starter Li-An

    (@li-an)

    The get_previous and get_next functions do not work for me… I tried get_adjacent too but with no result. echo get_permalink ( $prev ) show the URL of the actual post (same for $next)
    $story_id seems correct as echo get_permalink( $story_id ) gives the URL to the story custom post.

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘[Plugin: Posts 2 Posts] Display connect TO posts’ is closed to new replies.