Jump to content
Michael Steinmann

Question about comparing Pagefields of a Page and sorting them

Recommended Posts

Hello everyone,

i guess my php knowledge is not good enough to find a solution for the following problem:

I'm building a website where i have projects. Each project has tags like "webdesign, responsive, cms, print, flyer" etc. At the end of a project i want to recommend other projects, which have similar tags. I want to limit the recommendations to three other projects sorted by the hightest amount of same tags.

This is how far i got:

I'm using

<?php $interessantes = $pages->find("tags=$page->tags, id!=$page->id"); ?>

to find other projects with the same tags, excluding the page i'm already on.

Then i'm using three foreach-functions to go through the projects i found, the tags they have and compare them with the tags of the project i'm looking at. If i have two identical tags, i count up a variable.

<?php

// Projects i have found
foreach($interessantes as $interessant):

	$i = 0;

	// Tags of the projects i have found
	foreach($interessant->tags as $tag):

		// Tags of the project i'm looking at
		foreach($page->tags as $tagreferenz):

			if($tag == $tagreferenz):

				$i++;

			endif;

		endforeach;

	endforeach;

endforeach; 

?>

You can see what it looks like in the screenshot with a bit of HTML. I marked the tags of the current project green and the identical tags of other projects red with the amount of hits below. So in this example i would want to have three projects with three similar tags and get rid of those with only two and one.

59638598b25e1_Bildschirmfoto2017-07-10um15_28_35.thumb.png.e4da7ff689bac07de52411559deaf8a1.png

I guess i have to put my pages into an array (with the number of hits?), sort them and echo them with "limit=3"? Unfortunately i have no idea how to do this. You probably have an even better/shorter solution. Links to other topics are welcome to and i'll try to get my head around it.

If you need further explanation, i'll try my best.

Best regards

Share this post


Link to post
Share on other sites

@Soma wrote about his solution related to your problem, take a look:

 

  • Like 4

Share this post


Link to post
Share on other sites
16 hours ago, Sérgio Jardim said:

@Soma wrote about his solution related to your problem, take a look:

Thank you @Sérgio Jardim

I will have a look at it and try to get it to work. At least it sounds exactly like what i was trying to do.

I will respond if i am successful. ;)

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Spyros
      Hello
      I'm having a strange issue with the $page->find(), for some reason I'm missing some of the pages from the results. I found then that I was missing all the pages with the same "PAGE NAME". Is it a bug or am I missing something?
      PS 
      If I change the "PAGE NAME" of one of the missing ones then I'm retrieving the page without any problem.
      Thank you
    • By benbyf
      Hi, Looking to create form elements on a page–some input with a colection of form inputs and the appropriate labels and variables for that input. I've used ProForms in the past and rolled out my own when creating simply one off forms, but I wonder if anyone has found a good way of allowing form creation on page editing so that clients can adhocly make and edit forms?
      Thanks
    • By EyeDentify
      Hello Dear PW Gurus.

      Hope you fair well in these Corona Crisis times.

      Anyhow, i have a problem with a Cryptic error message that shows up when i am trying to Delete images out of a Images field.
      The Error message does say a little but it does not make sense to me why i can´t delete the images because of it.

      Is it some permission issue perhaps?

      I will attach screenshots of it and what i did prior to it.
      I am from sweden so ignore the funny words here and there.

      Hope you all can send me on the right track.
      i am running PW 3.0.139 on this install.

      Step1:

      Step 2: Select the images with the trashcan symbol

       
      Step 3: Cryptic Error message

      I am scratching my head on this one, have not seen this before.

      Thankfull for all help.
      /EyeDentify
    • By ngrmm
      i have a event-page with a table.
      first column in this table is page-reference-field
      how can i find out if a urlSegment matches one of the rows having the same page-reference-field (page-id)?
      // all guests $allguests = new pageArray(); foreach($page->event_guests_table as $event_guests_table_row) { $allguests->prepend($event_table_row->guest); } // echo allguests would output: 1101|1102|1103|… // domain.tld/event/1101/ // show content if guest is in the table or redirect if($input->urlSegment1 ~= $allguests ) { // show content } else { // redirect }  
      which selector operator do i have to use? the one above does not work
    • By ttttim
      Is there a way to add a (new or existing) page to the top of the asmSelect list? By default they're added at the bottom. 
×
×
  • Create New...