Jump to content

FeldtypePage category as blog


Anna
 Share

Recommended Posts

How to FieldtypePage category as blog?

Home
    - receptek
          - recept
          - recept
          - recept
    - kategorak
         - kategoria
         - kategoria
         - kategoria

recept.php
<?php
foreach($page->kat_page as $item) { //$item = kategoria
  echo "<h3>$item->title</h3>";

		//kategoria->recept???
}

 

Névtelen.png

Link to comment
Share on other sites

What's happening in the screenshot? Are you getting the same category where you should be getting three different categories? Is that the issue?

Otherwise a Page field that accepts multiple pages should suffice for assigning a post multiple categories. The code you've written should work.

However from

$kategoria->recept

I think you want to get to other receptek (recipes) related to a given category inside the loop. For that you can use 

$pages->find("kat_page=$item, id!=$page")

to find other recipes with the same category (excluding the current page).

Or as a more performant solution to get a 2-way relationship (to find categories related to a recipe AND recipes related to a certain category) you can use @Robin S's module

http://modules.processwire.com/modules/connect-page-fields/

  • Like 1
Link to comment
Share on other sites

Thank you!
 

<?php	
                    foreach($page->kat_page as $item) { //$item = kategoria	
                    $rec = $pages->find("kat_page=$item, id!=$page");
                        foreach($rec as $key) {//kategoria->recept
	                        echo "<div class='col-md-6 col-sm-6 col-lg-4'><div class='rec_item'>";
							foreach($key->images as $image) {
                                echo "<div class='img'><img class='resize' src='{$image->url}' alt='{$key->title}'></div>";
                            }		
							echo "<div class='desc_area'>
							    <a class='title' href='{$key->url}'>{$key->title}</a>
								<div class='desc dot is-truncated'>{$key->summary}</div>
							</div>
						</div>
					</div>";
                        }    
					}?>

Are you okay? Not much for forearch, can it be better?

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

×
×
  • Create New...