我目前正在尝试使用Kirby CMS的一些东西。
现在我正在尝试用一些图片构建一个简单的博客,我想要实现的是,博客文章中的第一张也是唯一的第一张图片,与文章的简短摘录一起显示在文章概述中.
所以我使用了 kirby 的 $page->images() 函数,它为我提供了帖子中所有图片的 url。但我只想要第一张照片!因为我找不到任何记录的选项来使用 kirby 函数执行此操作,所以我尝试在 php 中执行此操作。
我发现了什么:
-kirby 返回一个对象。
-我找不到任何 php 方法从对象中切出某些东西,所以我尝试将其转换为数组:
$pictureArray = (array) $article->images();
- 然后我尝试使用 array_slice,它返回了奇怪的结果,所以我仔细查看了我的数组。print_r($pictureArray); 返回这个:
Array ( [pagination] => [_] => Array ( [test.jpg] => image Object ( [meta] => Array ( ) [_] => Array ( [name] => test [filename] => test.jpg [extension] => jpg [root] => /home/exampledbq/www.example.com/kirby/content/01-articles/02-zweiter-Eintrag/test.jpg [uri] => content/01-articles/02-zweiter-Eintrag/test.jpg [parent] => files Object ( [pagination] => [_] => Array ( [article.txt] => variables Object ( [meta] => Array ( ) [_] => Array ( [name] => article [filename] => article.txt [extension] => txt [root] => /home/exampledbq/www.example.com/kirby/content/01-articles/02-zweiter-Eintrag/article.txt [uri] => content/01-articles/02-zweiter-Eintrag/article.txt [parent] => files Object *RECURSION* [modified] => 1354712997 [type] => content [variables] => Array ( [title] => Der zweite Eintrag [description] => Zusammenfassung. [published] => 18.12.2012 [tags] => Image, Article [text] => Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. (image: test.jpg) (image: test2.jpg) ) [filecontent] => Title: Der zweite Eintrag ---- Description: Zusammenfassung. ---- Published: 18.12.2012 ---- Tags: Image, Article ---- Text: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. (image: test.jpg) (image: test2.jpg) [languageCode] => en [template] => article ) ) [test.jpg] => image Object *RECURSION* [test2.jpg] => image Object ( [meta] => Array ( ) [_] => Array ( [name] => test2 [filename] => test2.jpg [extension] => jpg [root] => /home/exampledbq/www.example.com/kirby/content/01-articles/02-zweiter-Eintrag/test2.jpg [uri] => content/01-articles/02-zweiter-Eintrag/test2.jpg [parent] => files Object *RECURSION* [modified] => 1354713013 [type] => image [thumb] => image Object *RECURSION* [title] => test2 ) ) ) ) [modified] => 1354712200 [type] => image [thumb] => image Object *RECURSION* [title] => test ) ) [test2.jpg] => image Object ( [meta] => Array ( ) [_] => Array ( [name] => test2 [filename] => test2.jpg [extension] => jpg [root] => /home/exampledbq/www.example.com/kirby/content/01-articles/02-zweiter-Eintrag/test2.jpg [uri] => content/01-articles/02-zweiter-Eintrag/test2.jpg [parent] => files Object ( [pagination] => [_] => Array ( [article.txt] => variables Object ( [meta] => Array ( ) [_] => Array ( [name] => article [filename] => article.txt [extension] => txt [root] => /home/exampledbq/www.example.com/kirby/content/01-articles/02-zweiter-Eintrag/article.txt [uri] => content/01-articles/02-zweiter-Eintrag/article.txt [parent] => files Object *RECURSION* [modified] => 1354712997 [type] => content [variables] => Array ( [title] => Der zweite Eintrag [description] => Zusammenfassung. [published] => 18.12.2012 [tags] => Image, Article [text] => Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. (image: test.jpg) (image: test2.jpg) ) [filecontent] => Title: Der zweite Eintrag ---- Description: Zusammenfassung. ---- Published: 18.12.2012 ---- Tags: Image, Article ---- Text: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. (image: test.jpg) (image: test2.jpg) [languageCode] => en [template] => article ) ) [test.jpg] => image Object ( [meta] => Array ( ) [_] => Array ( [name] => test [filename] => test.jpg [extension] => jpg [root] => /home/exampledbq/www.example.com/kirby/content/01-articles/02-zweiter-Eintrag/test.jpg [uri] => content/01-articles/02-zweiter-Eintrag/test.jpg [parent] => files Object *RECURSION* [modified] => 1354712200 [type] => image [thumb] => image Object *RECURSION* [title] => test ) ) [test2.jpg] => image Object *RECURSION* ) ) [modified] => 1354713013 [type] => image [thumb] => image Object *RECURSION* [title] => test2 ) ) ) )
有谁知道这是什么吗?我的意思是图片网址在那里,但是这些东西到底是从哪里来的?当我尝试回显 $page->images() 函数时,它只返回图像 url 而不是整篇文章。
有人可以帮忙吗?也许甚至可以通过仅 kirby 函数而不是 php 来实现这一点?