Jump to content

How to add authors to your articles?


taoguang
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.

  • Like 3
Link to comment
Share on other sites

@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;

 

  • Like 1
Link to comment
Share on other sites

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?

  • Like 1
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...