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.
Is there any other way to display lyrics and chords so they are affected by the plugin?
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.
Is there any other way to display lyrics and chords so they are affected by the plugin?
Share Improve this question edited Jan 23, 2019 at 22:26 Kashif Rafique 2351 gold badge3 silver badges12 bronze badges asked Jan 23, 2019 at 21:23 Zoran KoprekZoran Koprek 235 bronze badges1 Answer
Reset to default 4First 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();