Jump to content

Creating a blog with 'Author' URL segment


sevfurneaux
 Share

Recommended Posts

Hi all,

I'm currently working on a 'Blog' section. Each article can be tagged and also shows the 'Author' of the post.

The tags are currently working with URL segments (almost identical to Ryan's post http://processwire.com/talk/index.php/topic,87.0.html).

And the tagging code looks like this:

if($tag = $sanitizer->selectorValue($input->urlSegment1)) { 
    $matches = $pages->find("tags*=$tag");
    echo $matches->render(); // or loop through and print on your own
}

Can the same be done for the 'Author' link? So if I created a author template that had URL segments, when Author link was clicked it would filter by createdUser.

I assume it would have to use $pages->find to find the createdUser somehow?

Cheers,

Sev

Link to comment
Share on other sites

Actually the author is a native database field, so no text searches are necessary. I've not performed this particular search before, but I think that this find below would work. The $user variable can either be a User object or a user ID number. So the following would find all pages created by the user viewing the page:

$matches = $pages->find("created_users_id=$user"); 

So if you were getting the user's name from the URL segment, you might do it like this:

<?php

if($input->urlSegment1) {
    $user = $users->get($input->urlSegment1); 
    if($user->id) {
        $matches = $pages->find("created_users_id=$user"); 
        echo $matches->render(); // or however you want to output the pages
    }
}
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...