Completed
Push — baseComponentsListPosts ( 2a73c9 )
by Markus
02:48
created

TimberHelper::getExcerpt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 6
dl 0
loc 16
rs 9.4285
1
<?php
2
3
namespace Flynt\Utils;
4
5
use Timber\Post;
6
7
class TimberHelper {
8
  public static function getTimberPostById($postId, $moreLinkText = null, $stripteaser = false) {
9
    global $post;
10
    $post = get_post($postId);
11
    setup_postdata($post, $moreLinkText, $stripteaser);
12
    $timberPost = new Post($post);
13
    wp_reset_postdata($post);
14
    return $timberPost;
15
  }
16
17
  public static function getExcerpt(
18
    $postId,
19
    $len = 50,
20
    $force = false,
21
    $readmore = "Read More",
22
    $strip = true,
23
    $end = "&hellip;"
24
  ) {
25
    global $post;
26
    $post = get_post($postId);
27
    setup_postdata($post, null, false);
28
    $timberPost = new Post($post);
29
    $excerpt = $timberPost->get_preview($len, $force, $readmore, $strip, $end);
30
    wp_reset_postdata($post);
31
    return $excerpt;
32
  }
33
}
34