taoguang Posted April 7, 2018 Posted April 7, 2018 Hello, How to add authors to your articles? ex you want to create a book library management system. Now i add a new page named authors, then add many authors in it. add a new page named books,then add many books in it. in book template, i add new field named author, and add link to the author page in the authors. Can anyone tell me how to complete it step by step?
Zeka Posted April 7, 2018 Posted April 7, 2018 Hi @taoguang Lest assume that you have this structure Books ( template: books ) - Book ( template: book ) - Book 1 ( template: book ) Authors ( template: authors ) - Author ( template: author) - Author 1 ( template: author) So to link author page to its books you have to create two page-reference fields: books and authors. The 'books' fields should use 'book' template as the selector and 'authors' field should use 'author' template as the selector. Then add 'books' field to 'author' template and 'authors' field to 'book' template'. Also, you can use this module https://modules.processwire.com/modules/connect-page-fields/ You can find why it would be helpful for your purpose by reading the description on its page. 3
taoguang Posted April 7, 2018 Author Posted April 7, 2018 How to write book's template? <?php echo "<h1>" . $page->title . "</h1>"; echo "<h3>" . $page->author . "</h3>"; ?> it just print author's id, i want print author's name and and add a link to author's page.
Zeka Posted April 7, 2018 Posted April 7, 2018 @taoguang It depends on your Page Refference field settings. If you have set 'Multiple pages', so to output author names foreach($page->authors as $author) { echo $author->title; } If 'Single page' echo $page->author->title; 1
taoguang Posted April 7, 2018 Author Posted April 7, 2018 yes,thank you. I had finish book's and author's page. book: <?php echo "<h1>" . $page->title . "</h1>"; foreach($page->author as $author) { echo "<h3><a href=\"$author->url\">" . $author->title . "</a></h3>"; } ?> author: <?php echo "<h1>" . $page->title . "</h1>"; echo "<h2>books:</h2>"; $id = $page->get('id'); $results = $pages->find("author=$id, limit=20"); foreach($results as $r) { echo "<a href=\"$r->url\">$r->title</a>"; } ?> And can be linked to each other, but i just add one page-reference field: author. is it ok? 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now