Skip to content

Commit

Permalink
add thumbnail directive
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish3 committed Nov 20, 2021
1 parent 3444705 commit 0eef525
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 44 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ In addition, entities contain contextual methods, as follows:
* `next` get next post
* `prev` get previous post
* `image` get post image
* `thumbnail` get post thumbnail (defined under Settings->Assets->Image Transforms->Blog Thumbnail)
* `excerpt` get post excerpt
* `content` get post content (supports Matrix field rendering. See below)

Expand Down
4 changes: 4 additions & 0 deletions src/behaviors/PostFieldsBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public function getImage()
return $this->owner->blogifyPostImage->one();
}

public function thumbnail() {
return $this->getImage()->setTransform(Handles::THUMBNAIL_TRANSFORM);
}

public function getExcerpt()
{
return $this->owner->blogifyPostExcerpt;
Expand Down
4 changes: 0 additions & 4 deletions src/templates/blogify/_partials/postThumbnail.twig

This file was deleted.

39 changes: 20 additions & 19 deletions src/templates/blogify/filters/_partials/postsList.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@
<div class="col-lg-4 mb-4">
<div class="entry2">
<a href="{{ post.url }}">
{% include 'blogify/_partials/postThumbnail' with {image:post.image,class:'img-fluid rounded'} %}
<div class="excerpt">
{% for category in post.categories.all() %}
<a href="{{ siteUrl }}/blog/category/{{ category.slug }}"
class="post-category text-white bg-secondary mb-3">{{ category }}</a>
{% endfor %}
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
<div class="post-meta align-items-center text-left clearfix">
<figure class="author-figure mb-0 mr-3 float-left">
<img src="{{ authorPhoto }}"
alt="{{ post.author.fullName }}"
class="img-fluid">
</figure>
<span class="d-inline-block mt-1">By <a
href="{{ siteUrl }}blog/author/?author={{ post.author.username }}">{{ post.author.fullName }}</a></span>
<span>&nbsp;-&nbsp; {{ post.postDate | date }}</span>
<img src="{{ post.thumbnail.url }}" alt="{{ post.thumbnail.title }}"
class="img-fluid rounded">
<div class="excerpt">
{% for category in post.categories.all() %}
<a href="{{ siteUrl }}/blog/category/{{ category.slug }}"
class="post-category text-white bg-secondary mb-3">{{ category }}</a>
{% endfor %}
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
<div class="post-meta align-items-center text-left clearfix">
<figure class="author-figure mb-0 mr-3 float-left">
<img src="{{ authorPhoto }}"
alt="{{ post.author.fullName }}"
class="img-fluid">
</figure>
<span class="d-inline-block mt-1">By <a
href="{{ siteUrl }}blog/author/?author={{ post.author.username }}">{{ post.author.fullName }}</a></span>
<span>&nbsp;-&nbsp; {{ post.postDate | date }}</span>
</div>
{{ post.excerpt }}
<p><a href="{{ post.url }}">Read More</a></p>
</div>
{{ post.excerpt }}
<p><a href="{{ post.url }}">Read More</a></p>
</div>
</div>
</div>
{% endfor %}
Expand Down
39 changes: 20 additions & 19 deletions src/templates/blogify/listing/_entry.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,28 @@
<div class="col-lg-4 mb-4">
<div class="entry2">
<a href="{{ post.url }}">
{% include 'blogify/_partials/postThumbnail' with {image: post.image, class:'img-fluid rounded'} %}
<div class="excerpt">
<a href="{{ siteUrl }}blog/category/{{ post.categories[0].slug }}"
class="post-category text-white bg-secondary mb-3">
{{ post.categories[0] }}
</a>
<img src="{{ post.thumbnail.url }}" alt="{{ post.thumbnail.title }}"
class="img-fluid rounded"/>
<div class="excerpt">
<a href="{{ siteUrl }}blog/category/{{ post.categories[0].slug }}"
class="post-category text-white bg-secondary mb-3">
{{ post.categories[0] }}
</a>

<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
<div class="post-meta align-items-center text-left clearfix">
<figure class="author-figure mb-0 mr-3 float-left">
<img src="{{ post.author.photo ? post.author.photo.url : '' }}"
alt="{{ post.author.fullName }}"
class="img-fluid">
</figure>
<span class="d-inline-block mt-1">By <a
href="{{ siteUrl }}blog/author?author={{ post.author.username }}">{{ post.author }}</a></span>
<span>&nbsp;-&nbsp; {{ post.postDate | date }}</span>
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
<div class="post-meta align-items-center text-left clearfix">
<figure class="author-figure mb-0 mr-3 float-left">
<img src="{{ post.author.photo ? post.author.photo.url : '' }}"
alt="{{ post.author.fullName }}"
class="img-fluid">
</figure>
<span class="d-inline-block mt-1">By <a
href="{{ siteUrl }}blog/author?author={{ post.author.username }}">{{ post.author }}</a></span>
<span>&nbsp;-&nbsp; {{ post.postDate | date }}</span>
</div>
{{ post.excerpt }}
<p><a href="{{ post.url }}">Read More</a></p>
</div>
{{ post.excerpt }}
<p><a href="{{ post.url }}">Read More</a></p>
</div>
</div>
</div>
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions src/templates/blogify/post/_entry.twig
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
{% for post in blogifyRecentPosts().limit(4).all() %}
<li>
<a href="{{ post.url }}">
{% include 'blogify/_partials/postThumbnail' with {image: post.image, class:"mr-4"} %}
<img src="{{ post.thumbnail.url }}" alt="{{ post.thumbnail.title }}" class="mr-4">
<div class="text">
<h4>{{ post.title }}</h4>
<div class="post-meta">
Expand Down Expand Up @@ -155,7 +155,7 @@
<div class="two-col d-block d-md-flex mb-4">
{% for post in entry.relatedPosts.limit(4).all() %}
<a href="{{ post.url }}" class="hentry v-height img-2 gradient ml-2"
style="background-image: url({{ post.image.url }});">
style="background-image: url({{ post.thumbnail.url }});">
<span class="post-category text-white bg-primary">
{{ post.categories[0] }}
</span>
Expand Down

0 comments on commit 0eef525

Please sign in to comment.