Permalink
Browse files

Schema.org implementation and some layout improvements

  • Loading branch information...
awmartin committed Mar 14, 2016
1 parent 614dff5 commit 7b8283b3fb397e5449b2dfa7ad3eae8deeec42e2
Showing with 201 additions and 67 deletions.
  1. +7 −8 null.layout.php
  2. +5 −5 null.loop.php
  3. +71 −54 null.post.php
  4. +118 −0 null.postmeta.php
View
@@ -3,11 +3,11 @@
/* Placeholders for future layout methods. */
function NullFullPage($content) {
return $content;
return NullSection($content);
}
function NullContentSidebar($content, $sidebar) {
$layout = '<div class="section"><div class="container"><div class="row">';
$layout = '<div class="row">';
$layout .= '<div class="eight columns">';
$layout .= $content;
@@ -17,13 +17,13 @@ function NullContentSidebar($content, $sidebar) {
$layout .= $sidebar;
$layout .= '</aside>';
$layout .= '</div></div></div>';
$layout .= '</div>';
return $layout;
return NullSection($layout);
}
function NullSidebarContent($content, $sidebar) {
$layout = '<div class="section"><div class="container"><div class="row">';
$layout = '<div class="row">';
$layout .= '<aside class="four columns">';
$layout .= $sidebar;
@@ -33,9 +33,9 @@ function NullSidebarContent($content, $sidebar) {
$layout .= $content;
$layout .= '</div>';
$layout .= '</div></div></div>';
$layout .= '</div>';
return $layout;
return NullSection($layout);
}
function NullSection($content, $options=array()) {
@@ -48,5 +48,4 @@ function NullSection($content, $options=array()) {
$options
);
}
?>
View
@@ -47,8 +47,10 @@ function EntryLayout($layout, $numColumns, $options=array()) {
'categories' => NullPostCategories(),
'tags' => NullPostTags(),
'posted_on' => NullPostedOn(),
'excerpt' => NullFirstParagraph()
'excerpt' => NullFirstParagraph(),
'format' => NullPostFormat()
);
$availableContent['titleplus'] =
$availableContent['categories']
.$availableContent['title']
@@ -82,11 +84,9 @@ function EntryLayout($layout, $numColumns, $options=array()) {
}
}
// Compute the item schema.
$post_format = NullPostFormat();
$item_type = "http://schema.org/BlogPosting";
$schema = NullPostSchema();
return NullTag('article', $content, array('class' => 'entry', 'itemscope' => null, 'itemtype' => $item_type));
return NullTag('article', $content.$schema, array('class' => 'entry'));
}
// Passing in a function as an argument.
View
@@ -36,38 +36,37 @@ function NullPostPagination() {
}
function NullEditPostLink() {
return return_edit_post_link(
__( 'Edit', 'plinth' ),
'<span class="edit-link">',
'</span>'
);
return return_edit_post_link(
__( 'Edit', 'plinth' ),
'<span class="edit-link">',
'</span>'
);
}
function return_edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) {
if ( !$post = get_post( $id ) )
return;
if ( !$post = get_post( $id ) ) return;
if ( !$url = get_edit_post_link( $post->ID ) )
return;
if ( !$url = get_edit_post_link( $post->ID ) ) return;
if ( null === $link )
$link = __('Edit This');
if ( null === $link ) {
$link = __('Edit This');
}
$post_type_obj = get_post_type_object( $post->post_type );
$link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>';
return $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
$post_type_obj = get_post_type_object( $post->post_type );
$link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>';
return $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after;
}
function is_post(){
return 'post' == get_post_type();
return 'post' == get_post_type();
}
function sep(){
return NullTag('span', ' | ', array('class' => 'sep'));
return NullTag('span', ' | ', array('class' => 'sep'));
}
function NullReadMoreLink() {
return NullTag('p', NullLink('Read more...', get_permalink()), array('class' => 'read-more'));
return NullTag('p', NullLink('Read more...', get_permalink()), array('class' => 'read-more'));
}
function NullExcerpt($attr=null) {
@@ -92,14 +91,7 @@ function NullFirstParagraph($asExcerpt=true) {
return $first_paragraph;
}
if (hasThumbnail()) {
$class = "excerpt";
} else {
$class = "excerpt no-thumbnail";
}
$attr = array('class' => $class);
return NullTag('div', NullTag('p', $first_paragraph), $attr);
return NullTag('p', $first_paragraph);
}
function getTextBetweenTags($string, $tagname) {
@@ -108,34 +100,37 @@ function getTextBetweenTags($string, $tagname) {
return $matches[1];
}
function NullContentWithoutFirstParagraph() {
$content = NullContent();
return str_replace(NullFirstParagraph(false), "", $content);
function NullPostContentWithoutExcerpt() {
$content = NullPostContent();
$content = str_replace(NullFirstParagraph(), "", $content);
// Remove that damned paragraph/span combination from the <!--more--> tag.
$content = preg_replace('/<p><span id="more-[0-9]"><\/span><\/p>/', "", $content);
return $content;
}
function NullPostTitle($entry=false) {
$title = get_the_title();
$permalink = get_permalink();
$linkTitleAttr = esc_attr(
sprintf( __( 'Permalink to %s', 'plinth' ),
the_title_attribute( 'echo=0' )
)
);
$linkAttr = array(
'title' => $linkTitleAttr,
'href' => $permalink,
'rel' => 'bookmark'
);
$linkToPost = NullTag('a', $title, $linkAttr);
$tag = "h1";
if ($entry) {
$tag = "h3";
}
$headerTitle = NullTag($tag, $linkToPost, array('class' => 'post-title', 'itemprop' => 'name'));
$title = get_the_title();
$permalink = get_permalink();
$linkTitleAttr = esc_attr(
sprintf( __( 'Permalink to %s', 'plinth' ), the_title_attribute( 'echo=0' ))
);
$linkAttr = array(
'title' => $linkTitleAttr,
'href' => $permalink,
'rel' => 'bookmark'
);
$linkToPost = NullTag('a', $title, $linkAttr);
$tag = "h1";
if ($entry) {
$tag = "h3";
}
$headerTitle = NullTag($tag, $linkToPost, array('class' => 'post-title'));
return $headerTitle;
return $headerTitle;
}
function hasThumbnail() {
@@ -146,21 +141,21 @@ function hasThumbnail() {
function NullPostThumbnail($size='medium', $placeholder=false) {
if (hasThumbnail()) {
$permalink = get_permalink();
$thumbnail = get_the_post_thumbnail(get_the_ID(), $size);
$linkAttr = array('href' => $permalink);
$thumbnail = get_the_post_thumbnail(get_the_ID(), $size); // <img />
$linkAttr = array('href' => $permalink);
$content = NullTag('a', $thumbnail, $linkAttr);
$attr = array('class' => 'thumbnail');
return NullTag('div', $content, $attr);
} else {
if ($placeholder) {
$attr = array('class' => 'thumbnail');
return NullTag('div', '&nbsp;', $attr);
} else {
$attr = array('class' => 'empty-thumbnail');
return NullTag('div', '&nbsp;<!--no thumbnail here-->', $attr);
$attr = array('class' => 'thumbnail empty');
return NullTag('div', '<!--no thumbnail here-->', $attr);
}
}
}
@@ -171,4 +166,26 @@ function NullPostFormat() {
return 'standard';
}
}
function NullIsPost() {
return NullPostType() == 'post';
}
function NullIsPage() {
return NullPostType() == 'page';
}
function NullPostType() {
global $post;
return $post->post_type;
}
function NullPostSlug() {
global $post;
return $post->post_name;
}
function NullIsAbout() {
return NullPostSlug() == 'about';
}
?>
View
@@ -16,4 +16,122 @@ function NullPostTags(){
function NullPostCategories() {
return get_the_category_list();
}
/*
{
"@context": "http://schema.org",
"@type": "LocalBusiness",
"address": {
"@type": "PostalAddress",
"addressLocality": "Mexico Beach",
"addressRegion": "FL",
"streetAddress": "3102 Highway 98"
},
"description": "A superb collection of fine gifts and clothing to accent your stay in Mexico Beach.",
"name": "Beachwalk Beachwear & Giftware",
"telephone": "850-648-4200"
}
*/
function NullPostSchema() {
global $schema_info;
$author_id = get_the_author_meta('ID');
$author_url = get_the_author_meta('url');
$author_avatar_url = get_avatar_url($author_id, 512);
$author_name = get_the_author();
$author = array(
'@type' => 'Person',
'name' => $author_name,
'url' => $author_url
);
$publisher_logo = array(
'@type' => 'ImageObject',
'url' => $schema_info['publisher_logo_url'],
'height' => $schema_info['publisher_logo_height'],
'width' => $schema_info['publisher_logo_width']
);
$publisher = array(
'@type' => 'Organization',
'name' => get_bloginfo('name'),
'logo' => NullJson($publisher_logo)
);
$title = get_the_title();
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $thumbnail_id, 'full' );
$image_src = $image[0];
$image_width = $image[1];
$image_height = $image[2];
if ($image_src) {
$image = array(
'@type' => 'ImageObject',
'url' => $image_src,
'height' => $image_height,
'width' => $image_width
);
} else {
$image = false;
}
$mainEntity = array(
'@type' => 'WebSite',
'@id' => get_bloginfo('url')
);
$type = NullIsPage() ? (NullIsAbout() ? 'AboutPage' : 'WebPage') : 'BlogPosting';
$schema = array(
'@context' => 'http://schema.org',
'@type' => $type,
'dateModified' => get_the_modified_date('c'),
'datePublished' => get_the_date('c'),
'name' => $title,
'headline' => $title,
'author' => NullJson($author),
'publisher' => NullJson($publisher),
'mainEntityOfPage' => NullJson($mainEntity)
);
if ($image) {
$schema['image'] = $image;
}
$content = '<script type="application/ld+json">';
$content .= NullJson($schema);
$content .= '</script>';
return $content;
}
function NullJsonKeyValue($key, $value) {
$quote = "\"";
$open = "{";
$colon = ":";
if (substr(trim($value), 0, 1) === $open) {
return $quote.$key.$quote.$colon.$value;
} else if (is_string($value)) {
return $quote.$key.$quote.$colon.$quote.$value.$quote;
} else {
return $quote.$key.$quote.$colon.$value;
}
}
function NullJson($attr=array()) {
$quote = "\"";
$open = "{";
$close = "}";
$keyValuePairs = array();
foreach ($attr as $key => $value) {
if (is_array($value)) {
$value = NullJson($value);
}
$keyValuePairs[$key] = NullJsonKeyValue($key, $value);
}
return $open.join(",", $keyValuePairs).$close;
}
?>

0 comments on commit 7b8283b

Please sign in to comment.