@@ -78,7 +78,7 @@ public function getFeaturedUrl($size = null)
78
78
);
79
79
80
80
//get the resized filename, otherwise serve the full size url
81
- if ( ! isset ($ attachmentMetadata ['sizes ' ][$ size ]['file ' ])) {
81
+ if ( ! isset ($ attachmentMetadata ['sizes ' ][ $ size ]['file ' ])) {
82
82
return $ this ->thumbnail ->attachment ->guid ;
83
83
}
84
84
@@ -93,7 +93,7 @@ public function getFeaturedUrl($size = null)
93
93
94
94
// Rebuild the url with the thumbnail image.
95
95
return $ imageUrl . implode ('/ ' ,
96
- array_merge ($ imageParts , [$ attachmentMetadata ['sizes ' ][$ size ]['file ' ]]));
96
+ array_merge ($ imageParts , [$ attachmentMetadata ['sizes ' ][ $ size ]['file ' ]]));
97
97
}
98
98
99
99
return $ this ->thumbnail ->attachment ->guid ;
@@ -119,10 +119,14 @@ public function getFeaturedAlt()
119
119
*
120
120
* @param null $mutators
121
121
*
122
+ * @param null $toReadMore
123
+ *
122
124
* @return string
123
125
*/
124
- public function getExcerpt ($ limit = 120 , $ mutators = null )
126
+ public function getExcerpt ($ limit = 120 , $ mutators = null , $ toReadMore = false )
125
127
{
128
+ $ content = $ this ->post_content ;
129
+
126
130
if (is_array ($ mutators )) {
127
131
foreach ($ mutators as $ mutator ) {
128
132
if (strlen ($ mutator ) < $ limit ) {
@@ -135,7 +139,11 @@ public function getExcerpt($limit = 120, $mutators = null)
135
139
$ limit -= strlen ($ mutators );
136
140
}
137
141
138
- return str_limit (strip_tags ($ this ->post_content ), $ limit );
142
+ if ($ toReadMore ) {
143
+ $ content = $ this ->getReadMore ($ content );
144
+ }
145
+
146
+ return str_limit (strip_tags ($ content ), $ limit );
139
147
}
140
148
141
149
/**
@@ -255,6 +263,7 @@ public function scopeHasCategories(Builder $builder, $slugs)
255
263
public function scopeHasTags (Builder $ builder , $ slugs )
256
264
{
257
265
$ builder ->whereHas ('taxonomies ' , function ($ query ) use ($ slugs ) {
266
+
258
267
$ query ->where ('taxonomy ' , '= ' , 'post_tag ' )->whereHas ('term ' , function ($ query ) use ($ slugs ) {
259
268
$ query ->whereIn ('slug ' , $ slugs );
260
269
});
@@ -318,7 +327,7 @@ public function shares()
318
327
[$ this ->post_name ]));
319
328
curl_setopt_array ($ curl , [
320
329
CURLOPT_RETURNTRANSFER => 1 ,
321
- CURLOPT_URL => $ url
330
+ CURLOPT_URL => $ url,
322
331
]);
323
332
324
333
$ response = curl_exec ($ curl );
@@ -391,9 +400,9 @@ public function newFromBuilder($attributes = [], $connection = null)
391
400
if (is_object ($ attributes ) && isset ($ attributes ->post_type )
392
401
&& array_key_exists ($ attributes ->post_type , static ::$ postTypes )
393
402
) {
394
- $ class = static ::$ postTypes [$ attributes ->post_type ];
403
+ $ class = static ::$ postTypes [ $ attributes ->post_type ];
395
404
} elseif (is_array ($ attributes ) && array_key_exists ($ attributes ['post_type ' ], static ::$ postTypes )) {
396
- $ class = static ::$ postTypes [$ attributes ['post_type ' ]];
405
+ $ class = static ::$ postTypes [ $ attributes ['post_type ' ] ];
397
406
} else {
398
407
$ class = get_called_class ();
399
408
}
@@ -406,4 +415,14 @@ public function newFromBuilder($attributes = [], $connection = null)
406
415
407
416
return $ model ;
408
417
}
418
+
419
+ /**
420
+ * Gets the posts content up to the read more tag
421
+ *
422
+ * @param $content
423
+ */
424
+ private function getReadMore ($ content )
425
+ {
426
+ return explode ('<!--more--> ' , $ content )[0 ];
427
+ }
409
428
}
0 commit comments