Jump to content

[SOLVED] How do I sort children pages by template?


Alpina
 Share

Recommended Posts

Hi,

My blog structure. The question is, how do I have the posts showing up before the categories and tags? Like below:

  • Blog -> template blog-index
    • Post 1 -> template blog-post
    • Post 2
    • Post 3
    • ...
    • Categories -> template blog-cat-index
      • Category 1 -> template blog-category
      • Category 2
      • Category 3
      • ...
    • Tags -> template blog-tag-index
      • Tag 1 -> template blog-tag
      • Tag 2
      • Tag 3
      • ...

Cheers

 

Edited by Alpina
Solved
Link to comment
Share on other sites

Hello @Alpina,

if your template blog-post has a date field and the other templates (blog-cat-index and blog-tag-index) not, you could sort the children of your template-blog-index by that date field.

Then the blog posts should be always before the categories and tags.

You can sort them in the template settings of your blog-index template under the family tab. That is how I like to do it.

You could also use a system date fields like created or modified, but then the categories and tags could get mixed in the sort order.

Regards, Andreas

Edited by AndZyk
  • Like 1
Link to comment
Share on other sites

hi,

well, first i must say for many reasons (seo, menu building, sitemap and so on) i wouldn't structure e blog this way, instead i would put the two parents (categories and tags) outside the main blog parent page and then use them with page reference and url segments but well...

now if you want to easily cheat, blog posts are usually ordered by reverse chronological order, then guess, add your date field to the, categories and tags parent pages and set them with a last century date 😄 job done, those two parent pages children can still be ordered the way you want

have a nice day

just modified to say @AndZyk was faster to have the same king of idea while i was writing 🙂

  • Like 3
Link to comment
Share on other sites

Hi,
sorry to be so late to answer, hit week... 🙂
actually it's quite simple, i would use your folder but this way

Blog -> template blog-index
    Post 1 -> template blog-post
    Post 2
    Post 3
    
Categories -> template blog-cat-index
    Category 1 -> template blog-category
    Category 2
    Category 3
    ...

Tags -> template blog-tag-index
    Tag 1 -> template blog-tag
    Tag 2
    Tag 3
    ...

then in your blog post template i would add two page-reference fields, one for the categories (parent => categories) and on for the tags (parent = well, guess :))
this way each post can easlily belong to various categories and have as many tags as you need
afterwards, for your main blog index template allowing page numbers and url segments it's easy to add a selection of the posts based on the categories and/or the tags with,, in both cases, the ability to have a pagination as well as for the main list of posts

depending on the way you want to filter your posts you'll just have to check the url segemnts, if only one (pagination or not, you can check if it is a category or a tag, if two either you decide the order (category/tag) or just check what kind is each one (easy to do making arrays of the available categories and tags to check in which one is which segment)

something more, this way, each post will just have only one url yoursite.com/blog/thepostname no matter from which selection you're coming avoiding many potential isszues with duplicate content, categories and tags being only a way to select which posts are displayed on your page

hope it's a little more explicit 🙂

have a nice day

  • Like 2
Link to comment
Share on other sites

  • Alpina changed the title to [SOLVED] How do I sort children pages by template?

@virtualgadjo

Maybe I am missing something, but your structure and the first structure achieve exactly the same result. The only difference is your structure uses one template (blog-index) with URL segments and the other one would use three templates (blog-index, blog-cat-index and blog-tag-index) and no URL segments.

I used the first structure (all inside blog with two page reference fields) many times with no downsides. So what I want to say: It is just a matter of preference. ✌️

Edited by AndZyk
Link to comment
Share on other sites

hI,

maybe i should explain a litte more 🙂 in the structure i use, blog posts are indeed children of the main blog page (and template, i'll go back to this later) and categories an tags are just a way to select which posts you want to display depending on url segments
the important thing to me is that, whatever "list" you're coming from, domain/blog/ domain/blog/tag_n/ domain/blog/cat_n/tag_,n/ and so on, when you click o a post its url will alwasys be domain/blog/post_n, no duplicate content, url segments making easy to use back to the list link, bookmark (and are prettier than js url hash but those could be used too)

now if you're sure (iron sure changing your mind would be painful to restructure), the posts will only belong to one category, @AndZyk's structure is a the best solution keeping only the tags outside the blog "folder"
---
Blog -> template blog-index
    Category 1 -> template blog-category
        Post 1 -> template blog-post
        Post 2
        Post 3
    Category 2
        Post 4
        Post 5
        Post 6
    Category 3
        Post 7
        Post 8
        Post 9
    ...

Tags -> template blog-tag-index
    Tag 1 -> template blog-tag
    Tag 2
    Tag 3
    ...

@Alpina, well yes and no 😄
first of all think of the blog with 50 say 100 posts, coming into the admin to add a category or a tag, i don(t know why but i think you would be happy to find those "folders" outside the main blog one instead of having to look for it under a tide of posts, less clicks, best life :) and as pw makes my life (and my clients' one) so easy, i try to keep it this way 🙂

the other thing, and in this case i'm always thinking i'm making the website for somebody else, friend, or client and not for me..,. i'm a huge fan of the children tab features which template is allowed for parent/children, in this case, when my victime clicks on the new button of the blog parent the created child has a blog_post template without having to choose (and make potential mistakes)
well you could say that setteing the category  and the tag parent templates on can't be used for new pages it would work too but think about the previous point i spoke about

i have maybe a strange habit but making a websit i always think
- as if it is not for me (well that's mainly the case 🙂 )
- think of it not as it is just when i'm making it but a few months or years after being used, sort of a reality principle and when thnking about a structure, i'm under a storm of "what if...?" (and so are my victims :D ) there must be no exceptions, each exception becoming a rule,  it makes things a liitle longer to decide but so more confotable to use afterwards...

well i think i should call it a post :D

have a nice day

  • Like 1
Link to comment
Share on other sites

Thank you for your explanation @virtualgadjo😀

My preferred structure looks like this:

  • Blog (template blog)
    • Post 1 (template post)
    • Post 2
    • ...
    • Categories (template categories)
      • Category 1 (template category)
      • Category 2
      • ...
    • Tags (template tags)
      • Tag 1 (template tag)
      • Tag 2
      • ...

The templates categories and tags have no template file, but category and tag have one.
The templates blog, category and tag have pagination enabled.
The post template hast two page reference fields: Category (single selection) and tags (multi selection).

This way there would be urls like:

  • blog/post1
  • blog/categories/category1
  • blog/tags/tag1

My structure would not allow for a post to have multiple categories and disconnects tags from categories.
Also I try not to use URL segments.

That would be the main difference between your and mine structure.
But of course there is no wrong or right structure. So everything is possible. 🙂

Have a nice day.

  • Like 2
Link to comment
Share on other sites

Hi @AndZyk

actually, the first thing i wuld think about is that when your post number grows, the two categories and tags folders will be a little less easy to find and modify but, honestly only an admin usability problem

for me, the important thing is what you say about this url thing and not allowing url segments (no security issue with them if you use a simple regex to say what you allow and a simple die if somebody puts something taht doesn't match nor is in the retreived/checked arrays) as, i must be used to too complicated demands of categories and/or tags selections and most of all, even with simple ones the necessity to allow mutiple categories for one post, if only one category allowed by post i would simplify the structure with the one i showed in the previous one as yours 😄

in the end, when it comes to seo the real important thingis this only one url for a blog post whichever list/category/tag you're linking from

and you are absolutely right, there no right or wrong structure, the only question for me is which one makes things the most simple to use depending on what you need (and, in a certain way, on who will use it, you and i are "a liitle" used to pw and its incredible features, it's not always the case of all the people we make website for and i tend to try and give them the most obvious admin i can, their love and addiction to pw will grow and let me be maybe a little more pw geeky along the website life 😄

Have a nice day

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...