Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter ayako1012

    (@ayako1012)

    Dear Agnes,

    Thank you for your reply.
    I’m afraid but I think Post 2 Postplugin leaves us more parts we can coding.

    So, I decided to try to make it with Post 2 Post plugin, but again I have some problem.

    I added

    /**
     * Related Post Connection
     * @author Bill Erickson
     * @link https://www.billerickson.net/manually-curated-related-posts/
     *
     * @uses Posts2Posts
     * @link https://github.com/scribu/wp-posts-to-posts/wiki
     */
    function be_post_type_connections() {
    
    	p2p_register_connection_type( array(
    		'name' => 'related-articles', // unique name
    		'from' => 'post',
    		'to' => 'post',
    		'title' => array( 'to' => 'All Connections', 'from' => 'Related Articles' )
    	) );
    }
    add_action( 'p2p_init', 'be_post_type_connections' );
    
    /**
     * Related Posts Before Loop
     * Adds connection data to $wp_query. Run before the loop.
     *
     * @author Bill Erickson
     * @link https://www.billerickson.net/manually-curated-related-posts/
     */
    function be_related_posts_pre_loop() {
     	// Make Sure plugin is active
     	if ( !function_exists( 'p2p_register_connection_type' ) )
    		return;
    
    	global $wp_query;
    	p2p_type( 'related-articles' )->each_connected( $wp_query );
    }
    /**
     * Display Related Posts
     * @author Bill Erickson
     * @link https://www.billerickson.net/manually-curated-related-posts/
     */
    function be_related_posts() {
     	// Make Sure plugin is active
     	if ( !function_exists( 'p2p_register_connection_type' ) )
    		return;
    
    	global $post;
    	if( isset( $post->connected ) && !empty( $post->connected ) ):
    		echo '<div class="related-posts">';
    		$count = 1;
    		foreach( $post->connected as $related ):
    			if( $count < 6 ) {
    				echo '<div class="related-post">';
    				echo '<a class="image" href="' . get_permalink( $related->ID ) . '">';
    				$cat = wp_get_object_terms( $related->ID, 'category', array( 'count' => 1 ) );
    				echo '<span class="category">' . $cat[0]->name . '</span>';
    				echo get_the_post_thumbnail( $related->ID, 'be_home_small' );
    				echo '</a>';
    				echo '<a class="title" href="' . get_permalink( $related->ID ) . '">' . $related->post_title . '</a>';
    				echo '</div>';
    				$count++;
    			}
    		endforeach;
    		echo '</div>';
    	endif;
    }

    to my function.php but the related posts never appears on each posts.

    If you know about this, I beg your ideas.

Viewing 1 replies (of 1 total)