/**
  * Metabox content
  *
  * @access public
  * @return void
  */
 public function callback($post)
 {
     echo "<div class='rp4wp_mb_manage'>\n";
     // Add nonce
     echo "<input type='hidden' name='rp4wp-ajax-nonce' id='rp4wp-ajax-nonce' value='" . wp_create_nonce('rp4wp-ajax-nonce-omgrandomword') . "' />\n";
     // Output plugin URL in hidden val
     echo "<input type='hidden' name='rp4wp-dir-img' id='rp4wp-dir-img' value='" . plugins_url('/assets/images/', RP4WP::get_plugin_file()) . "' />\n";
     // Create a Post Link Manager object
     $post_link_manager = new RP4WP_Post_Link_Manager();
     // Get the children
     $children = $post_link_manager->get_children($post->ID);
     echo "<div class='rp4wp_button_holder'>\n";
     // Build the related post link
     $url = get_admin_url() . "admin.php?page=rp4wp_link_related&amp;rp4wp_parent=" . $post->ID;
     // WPML check
     if (isset($_GET['lang'])) {
         $url .= "&amp;lang=" . $_GET['lang'];
     }
     echo "<span id='view-post-btn'>";
     echo "<a href='" . $url . "' class='button button-primary'>";
     _e('Add Related Posts', 'related-posts-for-wp');
     echo "</a>";
     echo "</span>\n";
     echo "</div>\n";
     if (count($children) > 0) {
         // Managet table
         echo "<table class='wp-list-table widefat fixed pages rp4wp_table_manage sortable'>\n";
         echo "<tbody>\n";
         $i = 0;
         foreach ($children as $link_id => $child) {
             $child_id = $child->ID;
             $edit_url = get_admin_url() . "post.php?post={$child_id}&amp;action=edit&amp;rp4wp_parent={$post->ID}";
             echo "<tr id='{$link_id}'>\n";
             echo "<td>";
             echo "<strong><a href='{$edit_url}' class='row-title' title='{$child->post_title}'>{$child->post_title}</a></strong>\n";
             echo "<div class='row-actions'>\n";
             echo "<span class='edit'><a href='{$edit_url}' title='" . __('Edit Post', 'related-posts-for-wp') . "'>";
             _e('Edit Post', 'related-posts-for-wp');
             echo "</a> | </span>";
             echo "<span class='trash'><a class='submitdelete' title='" . __('Unlink Related Post', 'related-posts-for-wp') . "' href='javascript:;'>";
             _e('Unlink Related Post', 'related-posts-for-wp');
             echo "</a></span>";
             echo "</div>\n";
             echo "</td>\n";
             echo "</tr>\n";
             $i++;
         }
         echo "</tbody>\n";
         echo "</table>\n";
     } else {
         echo '<br/>';
         _e('No related posts found.', 'related-posts-for-wp');
     }
     // Reset Post Data
     wp_reset_postdata();
     echo "</div>\n";
 }
예제 #2
0
function get_related_posts($id = NULL)
{
    // Get the current ID if ID not set
    if (!$id) {
        $id = get_the_ID();
    }
    // Post Link Manager
    $pl_manager = new RP4WP_Post_Link_Manager();
    // Get list of related posts
    $related_posts = $pl_manager->get_children($id);
    ob_start();
    include 'templates/related-posts.php';
    return ob_get_clean();
}
 /**
  * Generate the related posts list
  *
  * @param int $post_id
  * @param string $template
  * @param int $limit
  *
  * @return string
  */
 public function generate_related_posts_list($post_id, $template = 'related-posts-default.php', $limit = -1)
 {
     // the output
     $output = '';
     // get the post type
     $post_type = get_post_type($post_id);
     // The settings object
     $pt_settings = RP4WP()->settings['general_' . $post_type];
     // Post Link Manager
     $pl_manager = new RP4WP_Post_Link_Manager();
     // Get the children
     $related_posts = $pl_manager->get_children($post_id, array('posts_per_page' => $limit));
     // Count
     if (count($related_posts) > 0) {
         // Manager Template
         $manager_template = new RP4WP_Manager_Template();
         // Load the template output
         ob_start();
         $manager_template->get_template($template, array('related_posts' => $related_posts, 'heading_text' => $pt_settings->get_option('heading_text'), 'excerpt_length' => $pt_settings->get_option('excerpt_length'), 'post_type' => $post_type));
         $output = trim(ob_get_clean());
     }
     return $output;
 }