php 使用谷歌结构化数据的WordPress循环

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 使用谷歌结构化数据的WordPress循环相关的知识,希望对你有一定的参考价值。

<?php
// checks if there are any posts that match the query
if ( have_posts() ) :

// If there are posts matching the query then start the loop
while ( have_posts() ) : the_post(); ?>

<article id="post-<?php the_ID(); ?>" role="article" itemprop="hasPart" itemscope="" itemtype="http://schema.org/Article">
<meta itemscope='itemscope' itemprop='mainEntityOfPage' itemType='https://schema.org/WebPage'/>

    <!-- 1. Title Start -->
    <h1 itemprop="headline">
        <a href="<?php the_permalink(); ?>" itemprop="url">
            <?php the_title() ;?>
        </a>
    </h1>
    <!-- 1. Title End -->

    <!-- 2. Post Meta Start -->
    <p>
        <!-- 2.1 Published date Start -->
        Published on <span datetime="<?php echo the_time('c'); ?>" itemprop="datePublished" content="<?php echo the_time('c'); ?>">
            <?php the_time('M j, Y'); ?>
        </span>
        <!-- 2.1 Published date End -->
        
        <!-- 2.2 Author Start -->
        by <span class="post-author vcard" itemprop="author" itemscope itemtype="https://schema.org/Person">
        <span itemprop="name"><?php the_author(); ?></span>
        </span>
        <!-- 2.2 Author End -->
        
        <!-- 2.3 Category Start -->
        in <?php the_category(', '); ?>
        <!-- 2.3 Category End -->
    </p>
    <!-- 2. Post Meta End -->
    
    <!-- 3. Thumbnail Start -->
    <?php if ( has_post_thumbnail() ) { ?>
    <span itemprop="image" itemscope itemtype="https://schema.org/ImageObject">
        <a href="<?php the_permalink(); ?>" rel="bookmark">
            <?php the_post_thumbnail('medium'); ?>
        </a>

        <?php
        $thumb_id = get_post_thumbnail_id();
        $thumb_url_array = wp_get_attachment_image_src($thumb_id, 'medium', true);
        $thumb_url = $thumb_url_array[0];
        ?>
        <meta itemprop="url" content="<?php echo $thumb_url ?>">
        <meta itemprop='width' content='569'/>
        <meta itemprop='height' content='309'/>  
    </span>
    <?php } ?>
    <!-- 3. Thumbnail End -->
    
    <!-- 4. Content / Excerpt Start -->
    <span itemprop="description">
        <?php the_excerpt(); ?>
    </span>
    <!-- 4. Content / Excerpt End -->

    <div class="publisher-img" itemprop="publisher" itemscope itemtype="https://schema.org/Organization">
    <div itemprop="logo" itemscope itemtype="https://schema.org/ImageObject">
      <img src="http://ahmedkaludi.com/wp-content/uploads/2016/05/ak-logo.png" width="396" height="91"/>
      <meta itemprop="url" content="http://ahmedkaludi.com/wp-content/uploads/2016/05/ak-logo.png">
      <meta itemprop="width" content="232">
      <meta itemprop="height" content="90">
    </div>
    <meta itemprop="name" content="Ahmed Kaludi">
    </div>
    <meta itemprop="dateModified" content="<?php echo the_time('c'); ?>"/>
    
</article>

<?php
// Stop the loop when all posts are displayed
endwhile; ?>

<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>

<?php else: // If no posts were found ?>
    <p>Sorry, this post does not exist</p>
<?php endif; // End Loop ;) ?>

以上是关于php 使用谷歌结构化数据的WordPress循环的主要内容,如果未能解决你的问题,请参考以下文章

php 使用All in one SEO包的wordpress的结构化数据

一页中有多个 Wordpress 循环,产生相同的数据

php WordPress谷歌字体功能

php WordPress谷歌字体集成

PHP 手动加载(谷歌)Wordpress中的最新jQuery

PHP WordPress Enqueue jQuery - 谷歌CDN