Jump to content

Limits for fields


Cengiz Deniz
 Share

Recommended Posts

I am making a aporism site.  In my main page I put pepople and their apohrisms.

https://cdeniz.com/kisiler/

In another page I made tags.

https://cdeniz.com/konular/

Finaly i am making tag page. Related aphorisms will be together.

https://cdeniz.com/konular/sevgi/

and its source:

$kisiler= $pages->find("template=kisi,sort=title,repeater_ozlusoz=[ozlusoz_konusu=$page->id]");
$n=1;

foreach ($kisiler as $kisi) {
	
	foreach($kisi->repeater_ozlusoz as $aforism) {

	$tags = '';

		foreach ($aforism->ozlusoz_konusu as $tag) { $tags .= '<a href="'.$tag->url.'">'.$tag->title.'</a>&nbsp; &nbsp;'; }

   echo '<p>'.$n.'. <a href="'. $kisi->url .'">'.$kisi->title.'</a> : "<i>'. $aforism->ozlusoz.'</i>"<br/>&nbsp; &nbsp; Etiketler: '.$tags.' </p>';
   $n=$n+1; 
	}
	
echo "<hr>";
}

I passed very big code issues but now i can not go more. In tag the list related aphorisms come but with other aphorism which are belonging to person.

Capture.PNG.e78b8b1a0ec54cb67046b232c89017fe.PNG

Tag is "Sevgi". But second aphorism should be in the list. I could not exclude.

Sorry for my english. Thank you very much for your helps

Link to comment
Share on other sites

I solved. I added

 if ($tag->id == $page->id) 

 

$kisiler= $pages->find("template=kisi,sort=title,repeater_ozlusoz=[ozlusoz_konusu=$page->id]");
$n=1;

foreach ($kisiler as $kisi) {
	
	foreach($kisi->repeater_ozlusoz as $aforism) {

	$tags = '';

		foreach ($aforism->ozlusoz_konusu as $tag) { $tags .= '<a href="'.$tag->url.'">'.$tag->title.'</a>&nbsp; &nbsp;'; }
	if ($tag->id == $page->id) {
   echo '<p>'.$n.'. <a href="'. $kisi->url .'">'.$kisi->title.'</a> : "<i>'. $aforism->ozlusoz.'</i>"<br/>&nbsp; &nbsp; Etiketler: '.$tags.' </p>';
	$n=$n+1; }
	}
	
echo "<hr>";
}

 

Link to comment
Share on other sites

To introduce some other API methods you may not have tried yet...

// different way of matching subfield, and using simply $page
$kisiler = $pages->find("template=kisi, sort=title, repeater_ozlusoz.ozlusoz_konusu=$page");
foreach($kisiler as $kisi) {
    // you can use find() on your repeater PageArray
    $aforisms = $kisi->repeater_ozlusoz->find("ozlusoz_konusu=$page");
    foreach($aforisms as $key => $aforism) {
        // another way to get a numbered index
        // but maybe you should consider using ordered list markup instead?
        $num = $key + 1;
        // getting a string from a PageArray using the implode() method
        // and better to space your items with CSS than hardcode non-breaking spaces
        $tags = $aforism->ozlusoz_konusu->implode(' ', '<a href="{url}">{title}</a>');
        echo "<p>$num. <a href='$kisi->url'>$kisi->title</a>: <i>$aforism->ozlusoz</i><br>Etiketler: $tags</p>";
    }
    echo "<hr>";
}

 

  • 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

×
×
  • Create New...