Skip to content

Instantly share code, notes, and snippets.

@mattheu
Created August 27, 2015 13:57
Show Gist options
  • Save mattheu/f3cc89f09e28b95257f2 to your computer and use it in GitHub Desktop.
Save mattheu/f3cc89f09e28b95257f2 to your computer and use it in GitHub Desktop.
Post Objects Example
<?php
namespace Post_Objects;
class Post {
private $_post;
public function get_id() {
return $this->data->id;
}
public function get_title() {
return $this->data->title;
}
}
<?php
namespace USAT_Post_Objects;
class Post extends PostObjects\Post {
public function is_sponsored() {
$sponsored = lawrence_get_sponsored_post();
return $sponsored && $sponsored->ID === $this->get_id();
}
}
<?php $post = USAT\Post::get_by_id( 1 ); ?>
<h2><?php echo esc_html( $post->get_title() ); ?></h2>
<?php if ( $post->is_sponsored() ) : ?>
<p>Sponsored!</p>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment