Hallo zusammen,
Ich versuch gerade verzweifelt in mein wordpress die Piwik API Funktion DisplayTopKeywords einzubauen, nur leider bekomme ich kein Ergebnis, d.h es werden keine Keywords ausgegeben.
Mein Vorgehen ist wie folgt:
In einem PHP fähigen Widget kommt folgender Code:
<?php
// This function will call the API to get best keyword for current URL.
// Then it writes the list of best keywords in a HTML list
function DisplayTopKeywords($url = "" )
{
// Do not spend more than 1 second fetching the data
@ini_set("default_socket_timeout", $timeout = 1);
// Get the Keywords data
$url = empty($url) ? "http://". $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] : $url;
$api = "http://meinpiwik.tld/?module=API&method=Referers.getKeywordsForPageUrl&format=php&filter_limit=10&token_auth=meinauthcode&date=previous1&period=week&idSite=1&url=" . urlencode($url);
$keywords = @unserialize(file_get_contents($api));
if($keywords === false || isset($keywords["result"])) {
// DEBUG ONLY: uncomment for troubleshooting an empty output (the URL output reveals the token_auth)
// echo "Error while fetching the <a href='$api'>Top Keywords from Piwik</a>";
return;
}
// Display the list in HTML
$output = "<p>Top Keywords for <a href='$url'>$url</a></h2><ul>";
foreach($keywords as $keyword) {
$output .= "<li>". $keyword[0]. "</li>";
}
if(empty($keywords)) { $output .= "Nothing yet..."; }
$output .= "</ul>";
echo $output;
}
DisplayTopKeywords(); ?>
Ausgegeben bekomme ich aber überhaupt nix. Wenn ich jetzt vor dem "echo “Error while fetching…” die Kommentarzeichen wegmache gibts einen Link, der ganz vernünftig aussieht und als Inhalt des Links kommt folgendes:
a:10:{i:0;a:1:{i:0;s:22:"keyword1";}i:1;a:1:{i:0;s:22:"keyword´2";}i:2;a:1:{i:0;s:27:"keyword´3";}i:3;a:1:{i:0;s:32:"keyword4";}i:4;a:1:{i:0;s:23:"keyword5";}i:5;a:1:{i:0;s:18:"keyword6";}i:6;a:1:{i:0;s:27:"keyword7";}i:7;a:1:{i:0;s:27:"keyword8";}i:8;a:1:{i:0;s:23:"keyword9";}i:9;a:1:{i:0;s:23:"keyword10";}}
Hat jemand von Euch einen Tipp, wieso ich hier keine Anzeige bekomme?
Vielleicht bin ich ja einfach nur zu doof für PHP?