Non reciprocal
-
Have looked through the documentation and I’m not sure how to setup Posts 2 Posts with one way (non-reciprocal) links between pages. So when I add a connection inside one page – the page I’m connecting to doesn’t show a connection back.
Can anyone provide info on how to go about doing this?
Thanks.
-
Hi Elaine,
I’d like to learn more about this plugin and would like to help you out.
It sounds like you read this page?
https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage
It has this code listed at the top
<?php function my_connection_types() { p2p_register_connection_type( array( 'name' => 'posts_to_pages', 'from' => 'post', 'to' => 'page' ) ); } add_action( 'p2p_init', 'my_connection_types' ); ?>
When I add that code to my
functions.php
file and change it to<?php function my_connection_types() { p2p_register_connection_type( array( 'name' => 'pages_to_pages', 'from' => 'page', 'to' => 'page' ) ); } add_action( 'p2p_init', 'my_connection_types' ); ?>
I get “Connected Pages (to)” and “Connected Pages (from)” meta boxes in my edit pages admin.
Is this what you are looking for?
Hi Casey,
Thanks for your help.
I’ve setup the code above and have the links added via “Connected Pages (to)” appearing in sidebar.
What I’m looking for the plugin to do (if possible) is to only add a link one way e.g. say I have Page 1 and I want to link to Page 2 using the Plugin (so on Page 1 I add Page 2 via “Connected Pages (to)” – I only want the link to Page 2 to show on Page 1 i.e. if I then go to Page 2 I don’t want it to link back to Page 1. At the moment the Plugin automatically adds a link from page 2 to Page 1
Is it possible to setup the plugin so it only adds the link one way i.e. not reciprocal?
I think this is the page you are looking for.
https://github.com/scribu/wp-posts-to-posts/wiki/Reciprocal-connections
It sounds like you already have what you want.
The point of the plugin is to map and display relationships between objects. By default, the link only goes one way and it is *not* reciprocal:
Page1 -> Page2
Hence the ‘to’ and ‘from’. You must add a parameter
function my_connection_types() { p2p_register_connection_type( array( 'name' => 'pages_to_pages', 'from' => 'page', 'to' => 'page', 'reciprocal' => true ) ); } add_action( 'p2p_init', 'my_connection_types' );
Page1 <-> Page2
to turn on reciprocity. That get’s rid of the ‘to’ and ‘from’ idea, as they now belong to each other. There will now only be one meta box on each page, but it still shows on each page.So it sounds like you have what you want right now. Is it a matter of just removing the ‘from’ meta box? Ultimately, by design, if a post is linked to another, there will be a ‘link’ back to it (from). That doesn’t mean it is reciprocal though. It just explains the other half.
Hope this helps!
Hi Casey,
So adding
<?php function my_connection_types() { p2p_register_connection_type( array( 'name' => 'pages_to_pages', 'from' => 'page', 'to' => 'page' ) ); } add_action( 'p2p_init', 'my_connection_types' ); ?>
to the functions.php file show show “Connected Pages (to)” and “Connected Pages (from)” meta boxes in my edit pages admin and when I add a “to” fro page 1 to page 2 —- page 2 shouldn’t show a link back to page 1 by default. It’s only if I add ‘reciprocal’ => true that page 2 should link back to page 1?
Nope, Page2 should show a link back, a ‘from’ link.
There are two types of links, to and from. By default, when you link one post to another, the second post will have a ‘from’ link, no matter what. This is what is listed in the second post. This is not reciprocal, but a one way link. (from -> to)
To be reciprocal, both link must be ‘to’ links. They both link to each other. (to <-> to)
What you have currently is what you want. It is non-reciprocal. Pages have the ability to link to each other, but one link is the dominant one, showing a one way connection. (that is why there is to and from labels).
If two pages are connected, it will always show a link on both pages, whether it is reciprocal or not. A submissive page will still show where it is linked from.
Here is a real world example from the docs. It shows why it “links back.” Even though an employee doesn’t manage the manager, there is a need to show who manages the employee. If both employees managed each other (to <-> to), then it would be reciprocal.
Not-reciprocal:
p2p_register_connection_type( array( 'name' => 'employee_manager', 'from' => 'employee', 'to' => 'employee', 'cardinality' => 'one-to-many', 'title' => array( 'from' => 'Managed by', 'to' => 'Manages' ) ) );
Is there any way to turn off the linked from?
No as long as there is a link to it there will list a from link. Do you want to just hide it with CSS?
Would that be possible – I can’t see any difference in the HTML between a “to” and “from” link?
Do you know any other plugins that would allow just one link without having to hide anything?
looks like they are identical. If you do a jquery contains selector you could probably grab the ‘from’ text.
Something like:
$( "div#p2p-to-pages_to_pages h3 span:contains('from')" ).hide();"
ugly but should work
https://api.jquery.com/contains-selector/
No post-2-post is the best at this I think. Is there any reason why you need to hide it?
Building site for someone and they only want to pick what links to what i.e page 1 –> page 2 but not page 2 –> page 1 which is why I was also looking for a plugin that simply shows all pages and allows you to choose what links to display (without adding the link back).
Thank you for all your help (and time) – its much appreciated.
Since you’re linking pages to pages, you should be seeing two P2P metaboxes when editing a page in wp-admin. To show just one metabox, just set
'admin_box' => 'from'
in the parameters forp2p_register_connection_type()
.Docs: https://github.com/scribu/wp-posts-to-posts/wiki/Admin-box-display
- The topic ‘Non reciprocal’ is closed to new replies.