

term_id ); $pageTitle= $cat->name; $pageDesc = term_description( $cat->term_id, 'category' ) ?: ''; // grab first 5 posts $posts = get_posts([ 'cat' => $cat->term_id, 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC', ]); $listItems = []; foreach ( $posts as $i => $p ) { setup_postdata( $p ); $postUrl = get_permalink( $p ); $title = get_the_title( $p ); $date = get_the_date( 'c', $p ); $authorName = get_the_author_meta( 'display_name', $p->post_author ); $listItems[] = [ '@type' => 'ListItem', 'position' => $i + 1, 'item' => [ '@type' => 'BlogPosting', '@id' => $postUrl . '#blogposting', 'url' => $postUrl, 'headline' => $title, 'datePublished' => $date, 'author' => [ '@type' => 'Person', 'name' => $authorName, ], ], ]; } wp_reset_postdata(); $graph = []; // 1) WebSite + SearchAction $graph[] = [ '@type' => 'WebSite', '@id' => $homeUrl . '#website', 'url' => $homeUrl, 'name' => 'Yabby Casino Blog', 'potentialAction' => [ '@type' => 'SearchAction', 'target' => $homeUrl . '?s={search_term_string}', 'query-input' => 'required name=search_term_string' ] ]; // 2) Organization (publisher) $graph[] = [ '@type' => 'Organization', '@id' => $homeUrl . '#organization', 'name' => 'Yabby Casino Blog', 'url' => $homeUrl, 'logo' => [ '@type' => 'ImageObject', 'url' => $homeUrl . 'wp-content/uploads/logo.png' ], 'sameAs' => [ 'https://www.facebook.com/yabbycasino', 'https://twitter.com/yabbycasino' ] ]; // 3) BreadcrumbList $graph[] = [ '@type' => 'BreadcrumbList', '@id' => $pageUrl . '#breadcrumb', 'itemListElement' => [ [ '@type' => 'ListItem', 'position' => 1, 'name' => 'Home', 'item' => $homeUrl ], [ '@type' => 'ListItem', 'position' => 2, 'name' => $pageTitle, 'item' => $pageUrl ] ] ]; // 4) CollectionPage $graph[] = [ '@type' => 'CollectionPage', '@id' => $pageUrl . '#collection', 'url' => $pageUrl, 'name' => $pageTitle, 'description' => $pageDesc, 'isPartOf' => [ '@id' => $homeUrl . '#website' ], 'breadcrumb' => [ '@id' => $pageUrl . '#breadcrumb' ], 'hasPart' => [ '@id' => $pageUrl . '#itemlist' ] ]; // 5) ItemList of your posts $graph[] = [ '@type' => 'ItemList', '@id' => $pageUrl . '#itemlist', 'itemListElement' => $listItems ]; // output it all $json_ld = [ '@context' => 'https://schema.org', '@graph' => $graph ]; echo ''; });
Skip to main content