102 lines
3.0 KiB
PHP
102 lines
3.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Template Name: CollectiveAccess Test
|
|
*
|
|
* This is a template to test and display CollectiveAccess API results
|
|
*/
|
|
|
|
get_header();
|
|
?>
|
|
|
|
<div class="container mx-auto px-4 py-8">
|
|
<h1 class="text-3xl font-bold mb-8">Test de l'API CollectiveAccess</h1>
|
|
|
|
<?php
|
|
// Test getting objects
|
|
$objects = carhop_ca_get_objects([
|
|
'limit' => 10,
|
|
'page' => 1
|
|
]);
|
|
|
|
if (is_wp_error($objects)) {
|
|
echo '<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">';
|
|
echo '<strong class="font-bold">Erreur:</strong> ';
|
|
echo '<span class="block sm:inline">' . esc_html($objects->get_error_message()) . '</span>';
|
|
echo '</div>';
|
|
} else {
|
|
echo '<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">';
|
|
|
|
foreach ($objects as $object) {
|
|
echo '<div class="bg-white rounded-lg shadow-md overflow-hidden">';
|
|
|
|
// Display object image if available
|
|
if (isset($object['representations'][0]['urls']['preview'])) {
|
|
echo '<img src="' . esc_url($object['representations'][0]['urls']['preview']) . '"
|
|
alt="' . esc_attr($object['preferred_labels']['name']) . '"
|
|
class="w-full h-48 object-cover">';
|
|
}
|
|
|
|
echo '<div class="p-4">';
|
|
|
|
// Display object title
|
|
if (isset($object['preferred_labels']['name'])) {
|
|
echo '<h2 class="text-xl font-semibold mb-2">' . esc_html($object['preferred_labels']['name']) . '</h2>';
|
|
}
|
|
|
|
// Display object ID
|
|
echo '<p class="text-gray-600 text-sm mb-2">ID: ' . esc_html($object['object_id']) . '</p>';
|
|
|
|
// Display object type if available
|
|
if (isset($object['type'])) {
|
|
echo '<p class="text-gray-600 text-sm">Type: ' . esc_html($object['type']) . '</p>';
|
|
}
|
|
|
|
echo '</div>'; // End of card content
|
|
echo '</div>'; // End of card
|
|
}
|
|
|
|
echo '</div>'; // End of grid
|
|
}
|
|
?>
|
|
|
|
<div class="mt-8">
|
|
<h2 class="text-2xl font-bold mb-4">Collections</h2>
|
|
<?php
|
|
// Test getting collections
|
|
$collections = carhop_ca_get_collections([
|
|
'limit' => 5,
|
|
'page' => 1
|
|
]);
|
|
|
|
if (is_wp_error($collections)) {
|
|
echo '<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">';
|
|
echo '<strong class="font-bold">Erreur:</strong> ';
|
|
echo '<span class="block sm:inline">' . esc_html($collections->get_error_message()) . '</span>';
|
|
echo '</div>';
|
|
} else {
|
|
echo '<div class="grid grid-cols-1 md:grid-cols-2 gap-6">';
|
|
|
|
foreach ($collections as $collection) {
|
|
echo '<div class="bg-white rounded-lg shadow-md p-4">';
|
|
|
|
// Display collection name
|
|
if (isset($collection['preferred_labels']['name'])) {
|
|
echo '<h3 class="text-lg font-semibold mb-2">' . esc_html($collection['preferred_labels']['name']) . '</h3>';
|
|
}
|
|
|
|
// Display collection ID
|
|
echo '<p class="text-gray-600 text-sm">ID: ' . esc_html($collection['collection_id']) . '</p>';
|
|
|
|
echo '</div>';
|
|
}
|
|
|
|
echo '</div>';
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
get_footer();
|