-
Notifications
You must be signed in to change notification settings - Fork 16
Integrate "Microkid´s Related Posts" with Arlima
Victor Jonsson edited this page Jan 7, 2015
·
7 revisions
Here's an example of how to integrate MRP with Arlima.
functions.php
/**
* Get an array with related posts that can be used in Arlima's article templates.
* @param bool|int $post_id - Optional
* @return array|bool
*/
function get_related_posts( $post_id = false) {
global $post;
$data = false;
if( $post_id || is_object($post) ) {
if(!$post_id)
$post_id = $post->ID;
$related_posts = MRP_get_related_posts($post_id, true);
if( !empty($related_posts) ) {
$data = array('single' => count($related_posts) == 1, 'posts'=>array());
foreach ( $related_posts as $related ) {
$related->url = get_permalink ( $related->ID );
$stats = wp_count_comments($post_id);
if( is_object($stats) && !empty($stats->approved) )
$related->num_comments = $stats->approved;
$data['posts'][] = $related;
}
}
}
return $data;
}
// Add checkbox that can be used by editors to control whether
// or not related posts should be displayed in the article
add_action('arlima_list_manager_article_connection', function() { ?>
<label class="alignright">
Hide related posts:
<input type="checkbox" class="data hide-related" data-feature="hide_related" data-prop="options:hideRelated" />
</label>
<?php });
// Make related posts available in the article template
add_filter('arlima_article_related_content', function($count, $article, $post) {
if( !empty($post) && empty($article['options']['hideRelated']) )
return get_related_posts($article['post']);
return false;
}, 10, 3);
article.tmpl
...
{{#related}}
<div class="teaser-related-posts">
<aside>
{{#related.single}}
<h3>Read more</h3>
{{/related.single}}
{{^related.single}}
<h3>Related articles</h3>
{{/related.single}}
<ul>
{{#related.posts}}
<li>
<a href="{{url}}" class="related">{{post_title}}</a>
{{#num_comments}}
<span title="Number of comments" class="num-comments">
{{{num_comments}}}
</span>
{{/num_comments}}
</li>
{{/related.posts}}
</ul>
</aside>
</div>
{{/related}}
This Wordpress plugin was created by Swedish newspaper Västerbottens-Kuriren to give its editorial staff an easy to use tool for customizing the front pages of their online magazines.
- Download the latest release from github and unzip the folder in your plugin directory.
- Open up wp-admin and activate the plugin.
- Go to "Article lists" -> "Edit lists" in wp-admin and create your first article list.
- Open up a page (or create it) in wp-admin. Down to the right you will see a meta box labeled "Arlima" where you choose the list that you created on step 2.
- Go to "Article lists" -> "Manage lists" and start stuffing your article list with interesting content.