Forums

Posts 2 Posts
shortcode, template, the_content() (10 posts)

  1. Francois Lamotte
    Member
    Posted 11 months ago #

    Hello Scribu,

    I'm working with the shortcode templates. (latest version of your plugin)

    With the templates, I could reach every fields of a connected post/page except the_content();

    Everything else is displayed like :

    the_title();
    the_permalink();
    the_meta();

    But the_content(); creates a loop.

    I've tried some turnaround but as I not a dev, I'm not working in a proper way.

    Do you have any suggestion for me?

    Thank you,

    François

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Plugin Author

    Posted 11 months ago #

    Please post the relevant code (P2P filter + template file) in a http://pastebin.com

  3. Francois Lamotte
    Member
    Posted 11 months ago #

    Hi Scribu,

    Thank you for your answer.

  4. scribu
    Member
    Plugin Author

    Posted 11 months ago #

    You didn't post the relevant code, i.e. the code that takes a list of connected posts and loops through them.

    Also, I don't understand how P2P shortcodes are routed to templates. I assume the WP-Views plugin can only generate standard shortcodes, which implies that the code from P2P isn't used at all.

    Edit: what I'm asking for is your version of the code shown here:

    https://github.com/scribu/wp-posts-to-posts/wiki/Actions-and-filters

  5. Francois Lamotte
    Member
    Posted 11 months ago #

    In my functions.php, I've copied the shortcode handler from your wiki

    And in WP-VIEWS, my template is that one.

    From there, p2p shortcodes are calling the bunch of p2p-list-... .php templates that are rendered on that page.

    I don't know if this method is appropriate.

    Another question related to this logic, is that I'm interested to retrieve an URL value in a connected custom field, and to inject it into an other shortcode (for a video player). I retrieve the value but I don't understand yet how I will use it ... (the value is just under the picture (below VIDEO title).

    I'm sorry if i'm doing dumb stuff ... :-P

    F

  6. Francois Lamotte
    Member
    Posted 11 months ago #

    I've seen different kind of connexion like

    $connected = get_posts( array(
      'connected_items' => $zone_posts,
      'connected_type' => array( 'CONNECTION_TYPE1', 'CONNECTION_TYPE2', ... ),
      'connected_direction' => 'any',
      'post_type' => 'any',
      'suppress_filters' => false
    ) );

    But i don't know how to handle that with the shortcode logic. I'm sure that could help to reduce the number of queries.

    And after that as for each connexion I need to extract different fields, ... I am a little bit lost :-)

    F

  7. scribu
    Member
    Plugin Author

    Posted 11 months ago #

    Don't query multiple connection types unless you plan to show them together. The lower query count isn't worth the extra complexity.

    Back on topic: using the_content() works fine for me, since the $post global is changed before each template load.

    The only situation that I could imagine where this wouldn't work would be if you have a post connected to itself.

  8. Francois Lamotte
    Member
    Posted 11 months ago #

    For the topic the_content(), I understand that it works for you but I don't know how to handle it in my case.

    In the "master template", I need to place different shortcodes on multiple places. And each places has different elements to render.

    | p2p_cp_video_url | current_post_title + current_post_excerpt |
    | p2p_cp_sales_arg_content | p2p_cp_free_training_content |
    | p2p_cp_testimonial_title + excerpt | xxxx |

    So maybe I don't get the concept of templates for shortcodes, but I can't figure how to handle different pieces through one connexion and where to place that piece of code.

  9. Francois Lamotte
    Member
    Posted 11 months ago #

    or maybe the idea to use shortcodes for that kind of template is not a good one?

    going straight to standard templates will simplify the process?

  10. scribu
    Member
    Plugin Author

    Posted 11 months ago #

    going straight to standard templates will simplify the process?

    It might. Just don't start using p2p_list_posts(). :)

Reply

You must log in to post.

About this Plugin

About this Topic