I’m wondering what is the best way to organize book-page content without involving taxonomies. So for example, I have a math book with a bunch of problems that I wish to list. I have a custom post type qa
which can include a taxonomy <book-name>
, and I want the URL to be: <domain>/qa/<book-name>/<page-number>/<problem-number>
. So creating such a structure isn’t a big deal except the <page-number>
– there will be lots of pages, and I think that it is not practical to create so many taxonomies. So what will be the optimal implementation? I’d appreciate any suggestions.
1 comment
Comments are closed.
I don’t know if this is the optimal, it’s one suggestion.
For me I’d created the
qa
post type as hierachical.Then for every page in the book I’d created a child
qa
post usingmenu_order
field to handle the page number.This child has a 3rd level child for problems.
Hooking intro
pre_get_posts
forqa
archive, you can set thepost_parent
to 0, so in the archive view you get only books, and not the big list of pages and problems.Last thing to is create a rewrite rule that convert the url into some query vars.
E.g.
<domain>/qa/<book-name>/<page-number>/<problem-number>
should be rewritten inThat url will end in a very simple query where post id =
<problem-number>
.Example code:
In the single view template
single-qa.php
you can load sub tempalte for books, pages or problems, something like:Another snippet is for display the book title and the page number inside the problem template (
problem-content.php
according to previous snippet),Note that the code is a proof of concept and untested.