gnome Posted November 22, 2012 Share Posted November 22, 2012 Hi I've just found the related pages tutorial: http://processwire.com/videos/page-fieldtype/ Is it possible to do something similar, but rather than choose pages, to choose files? Thanks! Link to comment Share on other sites More sharing options...
diogo Posted November 22, 2012 Share Posted November 22, 2012 I'm not sure I understand your question completely, but you could use the page field for choosing files by having one file per page. You can do this by creating a field of the type "file" (let's name it "myFile"), and a template with only this field besides "title". Than, create a page "files", and the pages that use this new template as children of it. Now you can create a field of the type "page" (let's name it "myFiles") and choose the page "files" as the "Parent of selectable page(s)" on the input tab. To display the files chosen for a page you just have to do in the page template: foreach($page->myFile->myFiles as $f) echo $f->url; Link to comment Share on other sites More sharing options...
gnome Posted November 22, 2012 Author Share Posted November 22, 2012 Thanks diogo. I think maybe I've confused things. What I'm trying to achieve is a page where I can add PDFs to a page. Each PDF would belong to a category. Then I would loop through and show Category Name PDF 1 PDF 2 PDF 3 Is this possible? Thanks! Link to comment Share on other sites More sharing options...
diogo Posted November 22, 2012 Share Posted November 22, 2012 One file field for each category, maybe... Link to comment Share on other sites More sharing options...
onjegolders Posted November 22, 2012 Share Posted November 22, 2012 Gnome, To simplify: Would your files would each live on their own page, under a parent "Files"? Eg: Home About Contact Files -- File 1 -- File 2 Or do you want to be able to have "collections" of files eg: Home About Contact Files -- Brochures (can contain multiple files) -- Instructions (can contain multiple files) Do you then want to be able to link another page to these files or files collections? Or is it more simple and you just want a page where you display all your files under their respective heading (Brochures, Instructions) Sorry, just hard to understand exactly what you want to achieve. Link to comment Share on other sites More sharing options...
gnome Posted November 23, 2012 Author Share Posted November 23, 2012 Hi onjegolders It would be the simple version - a page where you display all your files under their respective heading (Brochures, Instructions) Link to comment Share on other sites More sharing options...
onjegolders Posted November 23, 2012 Share Posted November 23, 2012 Hi Gnome If you want it exactly like that, set up 3 templates in the backend (files, file_category and file_page) and make 1 template file (files.php) In your admin, make a Files page with template "files" then as children make Brochures and Instructions (file_category template) and then underneath these make a page for each file / or each collection of files (file_page) Eg: Home About Contact Files -- Brochures ---- Brochure 1 ---- Brochure 2 ---- Brochure Collection 1 -- Instructions ---- Instructions 1 ---- Instructions 2 ---- Instructions Collection 1 Then in your files.php file <?php include("./header.inc"); ?> <?php $file_categories = $page->children(); foreach ($file_categories as $category) { ?> <h3><?php echo $category->title; ?></h3> <ul> <?php foreach ($category->children() as $file_pages) { foreach ($file_pages->files as $file) { ?> <li> <a href="<?php echo $file->url; ?>"><?php echo $file->description; ?></a> </li> <?php } } ?> </ul> <?php } ?> <?php include("./footer.inc"); ?> Note that there may be more efficient ways of doing this, Brochures and Instructions could be there own main pages and in your template file you could find all pages with the "file_page" template and loop through the files but this way has it set up exactly how you want I think. Link to comment Share on other sites More sharing options...
gnome Posted November 23, 2012 Author Share Posted November 23, 2012 Thanks onjegolders, this sounds great. Will give it a go! Link to comment Share on other sites More sharing options...
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