Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

How to include "reading time" to blog posts?

Started by Frankenstein 7 years ago · 7 replies · 1026 views
7 years ago

Hi,

actually spending much time to get my grav blog working. So i installed the reading time plugin, but cant figure out clearly how to include it in blog posts.

Would appreciate help very much.

7 years ago

Hi @paulhibbitts, i'm using Striped. It would be very nice if the reading time stands also on the blog list on the view of every post and also in the blog post.

But unfortunately I can't do anything with Twig^^


Its would be very nice to get the striped like in the screenshot of it 😃

last edited 11/05/19 by Frankenstein
7 years ago

You will need to make small changes to Twig files in order to do that @yFStein. For example, to add reading time to the blog post listing page you would edit the blog_item.html.twig file. Here is an example of such an edit to get you going:

TWIG
    <header>
        {% if page.header.link %}
            <h2>
                {% if page.header.continue_link is not sameas(false) %}
                    <a href="{{ page.url }}"></a>
                {% endif %}
                <a href="{{ page.header.link }}">{{ page.title }}</a>
            </h2>
            {% else %}
            <h2><a href="{{ page.url }}">{{ page.title }}</a></h2>
        {% endif %}
        {% if page.header.description %}
        <p>{{ page.header.description }}</p>
        {% endif %}
        {{ page.content|readingtime }}
    </header>

To make sure any Twig modifications are not overwritten with future theme updates, you also should set up an inherited theme:
https://learn.getgrav.org/16/themes/customization#theme-inheritance

Hope the above helps.
Paul

7 years ago

Hi @paulhibbitts, i got another solution which is working a bit better and looks better, but u put me up to it.

Here it is:

TWIG
{% if page.header.author %}    
<span class="list-blog-author">
    <i class="fa fa-user"></i>
    {{ page.header.author }}
</span>
<br /><br />
{% endif %}

<span class="list-blog-author">
    Lesezeit: {{ page.content|readingtime }}
</span>
<br /><br />

{% if page.taxonomy.tag %}
<ul class="tags">
    <i class="fa fa-tag"></i>
    {% for tag in page.taxonomy.tag %}
    <li><a href="{{ base_url }}/tag{{ config.system.param_sep }}{{ tag }}">{{ tag }}</a></li>
    {% endfor %}
</ul>
{% endif %}

So i got the <br /><br /> double time cauz on mobile and on desktop its look terrible cauz the lines cutting itself. So its looks better.

Also i got the reading time in a span with class (for the look) from the author.

Now i would rlly prefer that stands their "9 Min 38 Sek" and not "9 MINUTES 38 SECONDS". You know how? 🙂

Another question to this:
Is their a way to show the tags from taxonomy among each other? Cauz this looks also absolute terrible when its cutting the tags. Would look better if its looks like this:

YAML
"tag_fontawesome_symbol" Tags:
- Tag One
- Tag Two
- Tag Three
last edited 11/05/19 by Frankenstein
7 years ago

I gotta changed:

TWIG
Lesezeit: {{ page.content|readingtime }}

to

TWIG
Lesezeit: {{ page.content|readingtime({'minutes_label': 'Min', 'minute_label': 'Min', 'seconds_label': 'Sek', 'second_label': 'Sek'}) }}

But their no changes 😕 (yes, synced (checked via ssh) and cleared cache)

//Edit
Found this on the Issue page of the plugin:
https://github.com/getgrav/grav-plugin-readingtime/issues/9

But dont know how to use the workaround from " mrNo0b"

last edited 11/06/19 by Frankenstein
7 years ago

I think you would do this following:

1) locate the file languages.yaml in the folder for the Reading Time Plugin
2) copy that file to your active theme folder (Striped for you I think)?
3) for your chosen language, edit the text strings for seconds etc

Please let me know if that in fact works🙂

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 104 18 hours ago
General · by pamtbaau, 23 hours ago
1 88 22 hours ago
General · by Andy Miller, 1 day ago
0 53 1 day ago
General · by Marcel, 12 months ago
6 381 5 days ago
General · by Duc , 6 days ago
3 69 6 days ago