Skip to content

Commit

Permalink
Adding Blog page and latest articles on homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Moraes committed Sep 23, 2018
1 parent 7827c4a commit d482761
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 135 deletions.
11 changes: 10 additions & 1 deletion front-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
use Basecamp\Models\Post;

$context = Timber::get_context();
$context['posts'] = new Timber\PostQuery();

$articles_args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'orderby' => array(
'date' => 'DESC'
)
);

$context['posts'] = new Timber\PostQuery($articles_args);

$context['is_front_page'] = true;

Expand Down
7 changes: 4 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

use Basecamp\Models\Post;

$context = Timber::get_context();
$context['posts'] = new Timber\PostQuery();
$context['pagination'] = Timber::get_pagination($pagination_mid_size);
$context = Timber::get_context();
$context['post'] = new TimberPost();
$context['posts'] = new Timber\PostQuery();
$context['pagination'] = Timber::get_pagination($pagination_mid_size);

Timber::render('index.twig', $context);
3 changes: 3 additions & 0 deletions resources/assets/sass/_common.sass
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ body
.slick__dots
text-align: center
margin-left: 0

.is-background-cover
background: $gray-dark center / cover no-repeat
9 changes: 9 additions & 0 deletions resources/assets/sass/_single.sass
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
.single
.main-article
position: relative

&__title
@extend .title
+mobile
font-size: 1.5rem
margin-bottom: 10px

+tablet
font-size: 3rem

.edit-post-link
margin-top: -1rem
Expand Down
19 changes: 19 additions & 0 deletions resources/assets/sass/pages/_blog.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

.blog

&__item

&-thumbnail
background: $gray-dark center / cover no-repeat
min-height: 190px
margin-bottom: 25px

&-title
@extend .title
margin-bottom: 8px !important

+mobile
font-size: 28px

&-meta
margin-bottom: 25px
3 changes: 2 additions & 1 deletion resources/assets/sass/pages/index.sass
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

@import tickets
@import tickets
@import blog
5 changes: 3 additions & 2 deletions resources/assets/sass/sections/_latest-articles.sass
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
text-decoration: underline

&__item
max-width: 436px
max-width: 584px
padding-top: 18px
padding-bottom: 18px

+tablet
display: flex
align-items: center

&-image
background-color: #E5E5E5
background: $gray-dark center / cover no-repeat
min-width: 150px
height: 150px
max-height: 150px
Expand Down
43 changes: 20 additions & 23 deletions resources/views/components/article.twig
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
<article class="base-camp-article post-type-{{ post.post_type }}" id="post-{{ post.ID }}">
<div class="blog__item column is-half-tablet is-one-quarter-desktop" id="post-{{ post.ID }}">

<header>
<h2 class="title is-h2">
<a href="{{ post.link }}">{{ post.title }}</a>
</h2>
<div class="article-meta">
<time class="timestamp"><i class="fa fa-calendar" aria-hidden="true"></i> <span>{{ post.date }}</span></time>
<div>
<a href="{{ post.author.link }}"><i class="fa fa-user" aria-hidden="true"></i> <span>{{ post.author }}</span></a>
</div>
{% if post.can_edit %}
<div><a href="{{ post.get_edit_url }}"><i class="fa fa-pencil" aria-hidden="true"></i> <span>{{ messages.article.edit }}</span></a></div>
{% endif %}
</div>
</header>
{% set post_thumb = TimberImage(post.thumbnail) %}

<a href="{{ post.link }}">
<div class="blog__item-thumbnail"
style="background-image: url('{{ post_thumb.src|resize(1320)}}')"></div>
</a>

<p class="content">{{ post.content }}</p>
<h2 class="blog__item-title">
<a href="{{ post.link }}">{{ post.title }}</a>
</h2>

{# Tags #}
<footer>
<div class="blog__item-meta article-meta">
<time class="timestamp"><i class="fa fa-calendar" aria-hidden="true"></i> <span>{{ post.date }}</span></time>
</div>

<p class="content">{{ post.preview.length(30).force }}</p>

<ul class="article-tags">
{% for tag in post.tags %}
{% for tag in post.tags %}
<li><a href="{{ tag.link }}" class="button is-danger is-outlined is-small">{{ tag.name }}</a></li>
{% endfor %}
</ul>
</footer>
{% endfor %}
</ul>

</article>
</div>
41 changes: 17 additions & 24 deletions resources/views/front-page.twig
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,26 @@

<div class="latest-articles column">
<h3 class="section-title">Latest Articles</h3>
<a href="#" class="latest-articles__see-all">See all articles</a>
<a href="/blog" class="latest-articles__see-all">See all articles</a>


<div class="latest-articles__items">
<div class="latest-articles__item">
<div class="latest-articles__item-image"></div>
<div class="latest-articles__item-content">
<div class="latest-articles__item-title">Lorem Ipsum Article Title here two lines</div>
<div class="latest-articles__item-copy">There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour.</div>
<a href="#" class="latest-articles__item-button">Read More</a>
</div>
</div>
<div class="latest-articles__item">
<div class="latest-articles__item-image"></div>
<div class="latest-articles__item-content">
<div class="latest-articles__item-title">Lorem Ipsum Blog Title here which is a little longer test</div>
<div class="latest-articles__item-copy">There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour.</div>
<a href="#" class="latest-articles__item-button">Read More</a>
</div>
</div>
<div class="latest-articles__item">
<div class="latest-articles__item-image"></div>
<div class="latest-articles__item-content">
<div class="latest-articles__item-title">Lorem Ipsum</div>
<div class="latest-articles__item-copy">There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour.</div>
<a href="#" class="latest-articles__item-button">Read More</a>
{% for post in posts %}
{% set post_thumb = TimberImage(post.thumbnail) %}

<div class="latest-articles__item">
<div class="latest-articles__item-image" style="background-image: url('{{ post_thumb.src|resize(600)}}')"></div>
<div class="latest-articles__item-content">
<div class="latest-articles__item-title">{{ post.title }}</div>

<div class="latest-articles__item-copy">
{{ post.preview.length(25).force }}
</div>

</div>
</div>
</div>
{% endfor %}

</div>
</div>

Expand Down
6 changes: 5 additions & 1 deletion resources/views/header/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
<section class="hero is-primary is-bold has-text-right">
<div class="hero__body">
<div class="container">
<h1 class="hero__body-title">{{ post.title }}</h1>
{% if function('is_single') %}
<h1 class="hero__body-title">Blog</h1>
{% else %}
<h1 class="hero__body-title">{{ post.title }}</h1>
{% endif %}
</div>
</div>
</section>
Expand Down
21 changes: 12 additions & 9 deletions resources/views/index.twig
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{% extends "base.twig" %}

{% block content %}
{% for post in posts %}
{% include 'components/article.twig' %}
<hr />
{% endfor %}


{% if posts.pagination.pages %}
{% include 'components/pagination.twig' %}
{% endif %}
<section class="blog section">
<div class="container">
<div class="columns">
{% for post in posts %}
{% include 'components/article.twig' %}
{% endfor %}
</div>
</div>
</section>

{% if posts.pagination.pages %}
{% include 'components/pagination.twig' %}
{% endif %}
{% endblock %}
66 changes: 35 additions & 31 deletions resources/views/single.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,43 @@

{% block content %}

<article class="main-article">
<h1 class="title is-2">{{ post.title }}</h1>
<h5 class="subtitle is-5">
<time class="timestamp">
<small>{{ post.date }} {{ post.time }}</small>
</time>
</h5>
{% if post.can_edit %}
<div class="edit-post-link"><a href="{{ post.get_edit_url }}">
<i class="fa fa-pencil" aria-hidden="true"></i> <span>{{ messages.single.edit }}</span></a>
<article class="main-article section">
<div class="container">
<div class="columns">
<div class="column is-three-quarters-desktop">
{% set post_thumb = TimberImage(post.thumbnail) %}
<h1 class="main-article__title">{{ post.title }}</h1>
<h5 class="subtitle is-5">
<time class="timestamp">
<small>{{ post.date }}</small>
</time>
</h5>
<div class="is-background-cover" style="height: 450px; margin-bottom:24px; background-image: url('{{ post_thumb.src|resize(1320)}}')"></div>
<p>
{{ post.content }}
</p>
</div>
{% endif %}
<p>
{{ post.content }}
</p>

</article>

{# Social media share buttons #}
{% include 'components/social-media.twig' %}

<section class="comment-box">
<div class="comments">
{% if post.comments is not empty %}
<h3 class="title is-3">{{ messages.single.comments }}</h3>
{% for comment in post.comments %}
{% include "comment.twig" %}
{% endfor %}
{% endif %}
</div>
</div>
</article>

{# Social media share buttons #}
{% include 'components/social-media.twig' %}

{% if post.comment_status == "open" %}
{% include "comment-form.twig" %}
<section class="comment-box section">
<div class="container">
<div class="comments">
{% if post.comments is not empty %}
<h3 class="title is-3">{{ messages.single.comments }}</h3>
{% for comment in post.comments %}
{% include "comment.twig" %}
{% endfor %}
{% endif %}
</section>
</div>

{% if post.comment_status == "open" %}
{% include "comment-form.twig" %}
{% endif %}
</div>
</section>
{% endblock %}
File renamed without changes.
Loading

0 comments on commit d482761

Please sign in to comment.