WordPress.org

Ready to get started?Download WordPress

Forums

CPT-onomies: Using Custom Post Types as Taxonomies
[resolved] Comics and stories (15 posts)

  1. Li-An
    Member
    Posted 2 years ago #

    Hello,
    I'm looking at your plugin because I try to put into a regular blog a comics section.
    I created with your plugin (very easy to use, thanks !) two custom posts:
    1. comics: each post will be a comics page (sorry not a WP page !)
    2. stories: each post is a story and I did CPT-onomy it and attach to comics

    To navigate between pages, there is no problem (I can use http://wordpress.org/extend/plugins/previous-and-next-post-in-same-taxonomy/ plugin). I hope I will manage to navigate between stories with your plugin - a problem I cannot manage with classic custom taxonomies as there is not "go to first post in next category".
    So, if I am in post 3 in story C, can I make a link to post 1 in story B or D (previous and next stories). Have you some idea how to get this ?

    http://wordpress.org/extend/plugins/cpt-onomies/

  2. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    Hi again =)

    So basically you would like to use the previous_post_link() and next_post_link() functions with your cpt-onomy instead of the default taxonomy "category"?

  3. Li-An
    Member
    Posted 2 years ago #

    Yes, something like this. There is no possibility to get "next/previous category" (I did not find) but, as with your plugin "categories" are "posts" too, I was hoping it could be possible.

  4. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    It's not possible right now but I'll add it for the next version.

    Thanks for pointing it out!

  5. Li-An
    Member
    Posted 2 years ago #

    Well, thank you for such a positive answer :-) I will wait for it.

  6. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    Just wanted to let you know version 1.0.2 is now available AND includes support for previous_post_link(), next_post_link(), prev_post_rel_link() and next_post_rel_link().

    global $cpt_onomy;
    $cpt_onomy->previous_post_link( $format, $link, $in_same_cpt_onomy, $excluded_term_ids, 'comics' );
    global $cpt_onomy;
    $cpt_onomy->next_post_link( $format, $link, $in_same_cpt_onomy, $excluded_term_ids, 'comics' );

    These CPT-onomy functions work exactly like the WordPress functions and take an extra parameter that allows you to designate which CPT-onomy to use for $in_same_cpt_onomy.

    I'm still working on adding these functions to the CPT-onomies documentation but they should be available within the next day or 2.

    I hope this is what you were looking for. Let me know if you come across any problems. Thanks!

  7. Li-An
    Member
    Posted 2 years ago #

    Thank you, I will take a look at it.

  8. Li-An
    Member
    Posted 2 years ago #

    Hello,
    well I'm a little lost - sorry I'm not a developper.
    You can see here what I managed to do
    http://tof.canardpc.com/view/2f4846a9-aef1-44d1-8da7-92f2b23f403b.jpg

    But I don't know how to insert a link to next and previous story in the page... If it's possible !

  9. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    Are you using the previous_post_link() and next_post_link() functions within The Loop?

    They are template tags and must be used in The Loop.

  10. Li-An
    Member
    Posted 2 years ago #

    Yes I did use them in the loop... and outside. It gives the same result aka the next and previous post in same custom post. But not the next or previous story.

    I use

    <?php next_post_link( '<strong>< %link</strong>' ); ?> ||
    <?php previous_post_link( '<strong>%link ></strong>' ); ?>

    It seems logic for me but it's not what I want :-)

  11. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    If you're wanting the link for the next post that's in the CPT-onomy 'stories', you have to use the CPT-onomy function: $cpt_onomy->next_post_link().

    If you just wanted the next post link, you could use next_post_link() but, because defining a CPT-onomy to overwrite the default taxonomy 'category' is a custom feature that's not available in the core WordPress function next_post_link(), I created a custom previous_post_link() and next_post_link() just for CPT-onomies.

    These CPT-onomy functions do mirror the WordPress functions, however, and accept the same parameters with the exception of an additional parameter that lets you define with CPT-onomy you want to use:

    global $cpt_onomy;
    $cpt_onomy->previous_post_link( '<strong>< %link</strong>', '', true, '', 'stories' );
    $cpt_onomy->next_post_link( '<strong>< %link</strong>', '', true, '', 'stories' );

    I've added previous_next_link() and next_post_link() to the CPT-onomies documentation if you need more information.

  12. Li-An
    Member
    Posted 2 years ago #

    Thank you for the time you give me !
    I have seen the documentation and now understand much better the function.
    But it does not want to work correctly :-(
    I inserted

    <?php global $cpt_onomy;
    $cpt_onomy->next_post_link( '<strong>...%link</strong>', '', true, '', 'stories' ); ?>||
    <?php global $cpt_onomy;
    $cpt_onomy->previous_post_link( '<strong>%link...</strong>', '', true, '', 'stories' ); ?>

    after checking stories is my name for the taxonomy. The link does not show. Looking at the source I've got:

    <strong>< <a href="http://www.li-an.fr/blogtest/comics/sf/" rel="next">SF</a></strong> ||
    <strong><a href="http://www.li-an.fr/blogtest/comics/dark-2/" rel="prev">Dark (2)</a> ></strong><br>
    ||
    <strong><a href="http://www.li-an.fr/blogtest/comics/dark-2/" rel="prev"></a>...</strong>

    The two first links are the regular "next_post_link" and previous.
    The next_post_link does not seem to produce anything and the previous_post_link gives the same result for the link but no text.

    http://tof.canardpc.com/show/ef15a863-7502-4c84-a128-1ef79d010380.html

    If you want I can give you the url of my test blog.

  13. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    It's no problem. Yea, send me the URL for your test blog.

    FYI: You don't have to do global $cpt_onomy twice. Once, at the beginning, will do the trick =)

  14. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    Ok. I figured out the problem. It seems that you have to define both of the first 2 parameters, $format and $link, of the $cpt_onomy->previous_post_link() and $cpt_onomy->next_post_link() functions for the link to print correctly. The functions were finding the previous and next post information but because $link was '', the printed link was empty.

    The easy fix: define $link (just put the default which is '%title').

    I apologize for this oddity. I just copied and pastied the WordPress previous_post_link() and next_post_link() to create $cpt_onomy->previous_post_link() and $cpt_onomy->next_post_link() and this weirdness never crossed my mind.

    I have updated the documentation to point out this issue and will "fix" this little bug for the next version.

    I hope this fixes everything. Let me know if it doesn't. Thanks!

  15. Rachel Carden
    Member
    Plugin Author

    Posted 2 years ago #

    Of course, now that I think about it some more, it makes sense that by defining $link as '' (which is empty), the printed link text would be empty (the function still prints the wrapper).

    AND, as strange as it sounds, I can imagine instances where you might not want the link text so I'll leave the setup as it is for now and update the documentation to make the $link parameter be required, unless you want the printed link text to be blank.

    Thanks for your help in finding this little gem =)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic