crear json datos structurados a partir de una galleria de imágenes en wp

0 votos
preguntado por guelo (1,450 puntos)

crear json datos structurados a partir de una galleria de imágenes en wp

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

if( has_shortcode( $post->post_content, 'gallery' ) ){  

echo '<script type="application/ld+json">{"@context":"http://schema.org/","@type":"ItemList","mainEntityOfPage":{"@type":"CollectionPage","@id":"'.$actual_link.'"},"itemListElement":[';

    preg_match('/\[gallery.*ids=.(.*).\]/', $post->post_content, $ids);

    $array_id = explode(",", $ids[1]);

    $images = $array_id;

    if ($images) {

        $image_list = '';  

        $position = 1;

        $attachmenturl='';

        $attachmenturlArray= array();


        foreach( $images as $image ) {

        if (is_front_page() && $position == 44) {

        break;

        }

            if ($ids != '') {

                $image = get_post($image);

            } 

            $attachmenturl=wp_get_attachment_url($image->ID);

            $attachmentimage=wp_get_attachment_image($image->ID, 'full' );

            $img_title = $image->post_title;

            $img_desc = $image->post_excerpt;

            if (!in_array($attachmenturl, $attachmenturlArray)) {

            if ($position == 1){

                $image_list .= '{"@type":"ListItem","position":'.$position.',"url":"'.$attachmenturl.'"}';

            } else {

            $image_list .= ',{"@type":"ListItem","position":'.$position.',"url":"'.$attachmenturl.'"}';

            }

            $position++;

            $attachmenturlArray[] = $attachmenturl;

            }

        }

        $position--;

        $image_list .= '],"numberOfItems":'.$position.'}</script>';  

        echo $image_list;               

   }

}

Por favor, accede o regístrate para responder a esta pregunta.

Bienvenido a Preguntas y respuestas para programadores o profesionales de la informática. Si tienes cualquier duda aquí obtendrás la respuesta.
...