Plugin Kirby-RelatedPages returns an empty object

Hey,

i want to use the Plugin Kirby-RelatedPages in my Blog.

Actually the usage is very simple (copy the example). But the function return an empty object with no data inside. Every article has tags.

object(Collection)#3040 (2) {
 ["pagination":protected]=>
 NULL
 ["data"]=>
  array(0) {
 }
}

Everyone with the same issue? Any idea to solve the problem?

This is how I use it:

<?php
    $options = array('startURI' => 'blog','searchField' => 'Keywords',);
    $MyRelatedPages = relatedpages($options);
?>

<?php if($MyRelatedPages->count() > 0): ?>
<h1><?php echo l::get('alsoInteresting') ?></h1>
<?php foreach ($MyRelatedPages->flip() as $MyRelatedPage): ?>
<?php if ($MyRelatedPage->status() == 'online'): ?>
<div class="h2"><a href="<?php echo $MyRelatedPage->url() ?>"><?php echo $MyRelatedPage->title() ?></a></div>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>

The major difference from the example is, I think,

<?php foreach($relpages as $relpage): ?>

instead of

<?php foreach(relatedpages() as $relpage): ?>

Gr. Bart

Hi,
thanks for your answer. But in PHP it makes no difference if i call the function and save the result in a variable or call the function directly.

i tried also this possibility.

Lukas

Have you tried contacting the plugin author directly (e.g. in his issues section: https://github.com/getkirby/plugins/issues) – he might be familiar with this problem?

Hi, it looks like the plugin just does not find any page. Could you give me details about your configuration, content structure and content pages?

Kind regards,
Uwe

Hi,

here is my structure of my content folder:

content
|-- 1-blog
|   |   |-- 409-der-traum-vom-offsitebackup
|   |   |-- article.text.txt
|   |   `-- headimage.jpg
|   |-- 410-vpn-unlimited-lebenslanger-account-fuer-35-euro
|   |   |-- article.text.txt
|   |   |-- headimage.jpg
|   |   |-- speedtest-england.png
|   |   |-- speedtest-frankfurt.png
|   |   |-- speedtest-ohne-vpn.png
|   |   `-- speedtest-usa.png
|   |-- 411-ios-8-2-schrittzaehler-deaktivieren
|   |   |-- article.text.txt
|   |   `-- headimage.jpg
|   |-- 412-mac-os-x-schatten-bei-screenshots-abschalten
|   |   |-- article.text.txt
|   |   `-- headimage.png
|   |-- 413-magicmockups-screenshots-in-natuerliche-umgebung-einbetten
|   |   |-- article.text.txt
|   |   |-- headimage.jpg
|   |   |-- magicmockups-download.png
|   |   `-- magicmockups.png
|   |-- 414-mit-ulysses-und-kirby-bloggen
|   |   |-- article.text.txt
|   |   |-- byword-style.png
|   |   |-- headimage.png
|   |   |-- ulysses-fussnote.png
|   |   |-- ulysses-link.png
|   |   |-- ulysses-markdown-syntax-1.png
|   |   |-- ulysses-markdown-syntax-2.png
|   |   |-- ulysses-rechtschreibung.png
|   |   `-- ulysses-style.png
|   |-- 415-erfahrungsbericht-amazon-trade-in-nachher-ist-man-immer-schlauer
|   |   |-- article.text.txt
|   |   `-- headimage.jpg

And an article.text.txt file:

Title: Mit Ulysses und Kirby bloggen
---- 
Date: 20-03-2015 11:53
---- 
Tags: Software, Kirby, Mac OS X
---- 
Description:
Mit Ulysses lassen sich Texte aller Art schreiben. Aber wie gut harmoniert das Schreib-Programm mit dem CMS Kirby?
---- 
Text:

In meinem [Blogging-Workflow][1] spielt [Byword][2] eine zentrale Rolle. Mit dem [Umstieg auf Kirby][3], ....

Regards Lukas

Hello Lukas,

I assume, you have already tried using the plugin with different options, first of all by using the searchItems option, because this would eliminate the problem of having no searchItem (“tag”) to search for. How did you implement it in your template?

What you could do to narrow down possible problems, is checking the different steps of the plugin by yourself. In your template:

  1. Is site()->children()->index() and site()->children()->index()->visible() finding any pages?
  2. If yes, loop through the pages, what is the output of PAGE->uri(), PAGE->id(), PAGE->depth() and PAGE->content()->get('tags')? These are the methods used by the plugin.

Hope this helps,
Uwe

Hi Uwe,

thanks for your reply. i check the methods from 1 and 2. They works all. But i guess i found the problem.

i copy line 128 in my template.

site()->activePage()->content()->get(str::lower('Tags))

It return nothing with echo. var_dump and print_r do not work because a timeout in php

In Line 163 are the same functions:

if (in_array($item,str::split($page->content()->get(str::lower($options['searchField']))))) { $hits++; }

And i guess that here is the same problem.

I can also send you my whole blog and you can look by yourself.

Regards Lukas

Hi Lukas, you can send me the blog and I will have a look into it.

I think, your code does not contain the typo above (missing closing quote in str::lower), does it?

Line 128 is supposed to get the items in the field (“Tags”) of the current page, which should be searched for in all other pages (this is done in line 162. Of course, there have to be items in the current page or you have to supply tags to search for.

BTW, which version of Kirby you are using?

Kind regards,
Uwe

Hi,

Sorry, that was a typo by myself.

I use the current version of kirby.

Regards.

Hi all,

it turns out that the problem has been caused by the routing configuration. When implementing the routing configuration as it is outlined here, everything is working fine.

See also this post.

Kind regards,
Uwe