Related post for custom post type is not working.
-
I am creating a custom theme and getting trouble when trying to add related post.
Custom post: albums
single-album.php<?php /** * The template for displaying all single posts. * * @package MusiKian */ get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?> </header><!-- .entry-header --> <div class="section group"> <div class="col x9 entry-content"> <?php the_content(); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'musikian' ), 'after' => '</div>', ) ); ?> </div><!-- .entry-content --> <div class="col x3"><?php include 'widget/contentad.php'; //contentad.php is empty ?></div> </div> <footer class="entry-footer"> <?php musikian_entry_footer(); ?> </footer><!-- .entry-footer --> </article><!-- #post-## --> <!--related post --> <?php $orig_post = $post; global $post; $categories = get_the_category($post->ID); if ($categories) { $category_ids = array(); foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id; $args=array( 'post_type' => 'albums', 'category__in' => $category_ids, 'post__not_in' => array($post->ID), 'posts_per_page'=> 2, // Number of related posts that will be shown. 'caller_get_posts'=>1 ); $my_query = new wp_query( $args ); if( $my_query->have_posts() ) { echo '<div id="related_posts"><h3>Related Posts</h3><ul>'; while( $my_query->have_posts() ) { $my_query->the_post();?> <li><div class="relatedthumb"><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a></div> <div class="relatedcontent"> <h3><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> <?php the_time('M j, Y') ?> </div> </li> <? } echo '</ul></div>'; } } $post = $orig_post; wp_reset_query(); ?> <!-- end of related post --> <?php // If comments are open or we have at least one comment, load up the comment template if ( comments_open() || get_comments_number() ) : comments_template(); endif; ?> <?php endwhile; // end of the loop. ?> </main><!-- #main --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>
It return
Parse error: syntax error, unexpected ‘endwhile’ (T_ENDWHILE) in E:\Xampp2\htdocs\bdalbum\wp-content\themes\musikian\single-albums.php
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Related post for custom post type is not working.’ is closed to new replies.