Jump to content

[SOLVED] Real estate site - project on start page


brandy
 Share

Recommended Posts

Hi!

I´m building my first website with Processwire, after changing from some other CMS.
As the title says, it´s for a real estate company, which has several projects.

I made a home-template, a project-template and one template for the apartments with a working menu.
The site-structur is this one:
Home
--> Project
     --> Apartment
          --> Apartment 1
          --> Apartment 2
          --> Apartment 3
          --> Apartment 4
          --> ...

Now, I want to have the projects shown on the homepage. One project should be the "main"-project.
To do so, I need the data from the several subpages. How do I get the information to the top or to another location?
My customer should be able to choose which project should be on top!

Thanks a lot!

Link to comment
Share on other sites

Hi Brandy and welcome to ProcessWire

There are many ways to achieve what you want. Hardest part is deciding which method works best for you and you client, eg:

  1. On your home page template you could have a Page reference field that allows your client to choose the featured projects and make the first the "main" project. For output, loop through the chosen page references and ensure the main project (page reference Project #1), gets different, more prominent styling.
  2. Use Tags on Project pages, eg "Home page featured" & "Home page other". Then in your home page template, use a selector to get the featured projects and loop through as above

Based on info you supplied, I'd go with option 1

Hope this helps

 

Link to comment
Share on other sites

Have a look at delayed output strategy. You have one main "template"(_main.php) & can then simply create a new template for a sub-section page where you just add code for regions/sections of your _main template where you want to show different content (summaries, other content etc.).

I found the intermediate templates a good starting point to see how _main.php & e.g. home.php or basic.php interact.

Once you've learnt this, look at markup regions - super powerful (once mastered)!

Link to comment
Share on other sites

Those subpages are now linked to your home page and you change your home page template to show what fields you want. For example, if your page reference field is called 'featured', in your home page template you can choose what fields you need to show from the subpage.

<?php foreach ($page->featured as $apartment) :
  if ($page->featured->first->id == $apartment->id) :
    // it's the first one
    ?>
      <div class='featured first'>
        <h2><?=$apartment->title?></h2>
        <p>Bedrooms: <?=$apartment->bedrooms?></p>
        <p>Bathrooms: <?=$apartment->bathrooms?></p>
        <p>Price: <?=$apartment->price?></p>
      </div>

	<?php else:
  	// it's not the first one
  	?>
      <div class='featured'>
        <h3><?=$apartment->title?></h3>
        <p>Bedrooms: <?=$apartment->bedrooms?></p>
        <p>Bathrooms: <?=$apartment->bathrooms?></p>
        <p>Price: <?=$apartment->price?></p>
      </div>
  <?php endif; 
endforeach; ?>

 

  • Like 2
Link to comment
Share on other sites

Hi again!

Thanks a lot for your help.
Now I have a very basic question:
I have numerous fields for every detail of the project (size, rooms, etc.).

Now I want to show the different fields on the site.
The image is shown via:

<?php if($page->site_main_image) echo "<img src='{$page->site_main_image->url}' alt='$image->description' />"; ?>

How do I show a field?
I tried with:

<?php if($page->project_app_floor) echo "<td>{$pages->get("project_app_floor")}</td><td>{$pages->get("project_app_floor")}</td>"; ?>

I don't really know, if I have to refer to the field directly or if I need the page.
Thanks a lot!
 

Link to comment
Share on other sites

Welcome to the forums and to ProcessWire @brandy :-).

39 minutes ago, brandy said:

Now I have a very basic question:

 

40 minutes ago, brandy said:

I don't really know, if I have to refer to the field directly or if I need the page.

I don't know how much of the docs and/or tutorials you have gone through already. If you haven't already seen the docs about $page and $pages. I'll also throw in selectors. You'll get along better and farther with these under your belt.

  • Like 1
Link to comment
Share on other sites

Yeah, I have been going throug many pages, but I don´t understand how I get down to a field.
I mean getting the properties of a page, like the image in the example above is clear and I do understand.
But I´m not able to move it to a field. The direct way

{$page->FIELDNAME->label}

doesn´t work.

So I tried a different way

$fields->get("FIELDNAME")

I guess you guys are laughing your heads off :-)
I´m totally confused at what end I am, and where to look for the field and its content...

 

Link to comment
Share on other sites

Hi @brandy and welcome to the forum.

First, no one laughs.

Second, take a look at this older post.

Lastly, just an FYI, you can better search the forum content by typing this into your browser: site:processwire.com/talk {search terms}  or you can use /blog rather than /talk to search the blog articles.

You'll find that everyone here is both knowledgeable and willing to help, so please ask away!

Link to comment
Share on other sites

20 minutes ago, brandy said:

I guess you guys are laughing your heads off :-)

Definitely not! That's not how we roll in this community.

20 minutes ago, brandy said:

I´m totally confused at what end I am, and where to look for the field and its content...

I guess you should start here then?

https://processwire.com/docs/start/templates/

20 minutes ago, brandy said:

Yeah, I have been going throug many pages, but I don´t understand how I get down to a field.
I mean getting the properties of a page, like the image in the example above is clear and I do understand.

It's always the name of the field :-)

<?php namespace ProcessWire;
// will yield its value
// @note: the value can be as simple as a string or integer, or more complex, e.g. an array or object
// @note: that field must be present in the template that this page uses
$page->name_of_field;

In other words the 'name of the field' is a property (some would say attribute) of that page. Just like things (humans, buildings, animals, etc) have properties/attributes: height, width, etc. 

Edit

Also note that $page always refers to the current page, but the principle of 'name_of_field' still applies. For example:

<?php namespace ProcessWire;

// this page we are viewing
// get a property from it.
$height = $page->height;// height is the name of an integer field in the template used by this page
echo $height;
// get another page not currently in view
// get it using its ID
$anotherPage = $pages->get(1234);
// this other page uses the same template as our 'current page' above
// so, we can get its height property as well
$anotherPageHeight = $anotherPage->height;
echo $anotherPageHeight;
// @note: we only echo 'simple' field values, i.e. those that do not return an array or an object, etc

 

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

  • 3 weeks later...
On 10/19/2020 at 10:18 PM, psy said:

Those subpages are now linked to your home page and you change your home page template to show what fields you want. For example, if your page reference field is called 'featured', in your home page template you can choose what fields you need to show from the subpage.


<?php foreach ($page->featured as $apartment) :
  if ($page->featured->first->id == $apartment->id) :
    // it's the first one
    ?>
      <div class='featured first'>
        <h2><?=$apartment->title?></h2>
        <p>Bedrooms: <?=$apartment->bedrooms?></p>
        <p>Bathrooms: <?=$apartment->bathrooms?></p>
        <p>Price: <?=$apartment->price?></p>
      </div>

	<?php else:
  	// it's not the first one
  	?>
      <div class='featured'>
        <h3><?=$apartment->title?></h3>
        <p>Bedrooms: <?=$apartment->bedrooms?></p>
        <p>Bathrooms: <?=$apartment->bathrooms?></p>
        <p>Price: <?=$apartment->price?></p>
      </div>
  <?php endif; 
endforeach; ?>

 

@psy: How do I filter out only some fields from the page, linked via the page reference field?
Can I use the fields from the referenced page in the template of the current site?

 

Link to comment
Share on other sites

  • 2 weeks later...

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...