2

I have Custom Post Type "pjesma" (song), and the only way I managed to display the content is like archive-pjesma.php.

It works fine:

<?php get_header();
global $post;
$args = array( 'post_type' => 'pjesma', 'posts_per_page' => 10 );
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) :
  setup_postdata( $post ); ?>
  <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
  </h2>
<?php //the_content(); ?>
<?php endforeach; 
wp_reset_postdata(); 

get_footer(); ?>

Then in single-pjesma.php I can only use the_title() so I use this echo $post->post_content;. Content of single-pjesma.php:

<?php get_header(); ?>
<?php
echo "<h1>"; the_title();
echo "</h1>";
echo $post->post_content;
?>
<?php get_footer(); ?>

Now, the problem is that I have installed plugin Chords and Lyrics so I can properly display chords above lyrics and that plugin does not affect the content. Content is displayed as it is stored in the database I guess.

enter image description here

Is there any other way to display lyrics and chords so they are affected by the plugin?

4

First of all, you shouldn't use get_posts on your CPT archive - WP already creates a query and selects posts that should be display in there. So your archive-pjesma.php should look like this:

<?php get_header(); ?>

<?php while ( have_posts() ) : the_post(); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php // the_content(); ?>
<?php endwhile; ?>

<?php get_footer();

And you also should use simplified version of loop in your single-pjesma.php:

<?php get_header(); ?>

<?php if ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endif; ?>

<?php get_footer();
  • Cool, this works, just had to put endif; to close if. – Zoran Koprek Jan 23 at 21:56
  • Right, sorry for that - I've already fixed it. – Krzysiek Dróżdż Jan 23 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.