I try to customize my own post using the shortcode way in wordpress. I want to display the post according to its category.

<?php

function sample_post($atts) {
   extract(shortcode_atts(array(
      'category_name' => 'uncategorized'
   ), $atts));

  $args = array('category_name' => $category_name);
   query_posts($args);
   if (have_posts()) : while (have_posts()) : the_post(); ?>
         <label><?php the_title(); ?></label>
   <?php
        endwhile;
   endif;
}

add_shortcode('sample_post', 'sample_post');

?>

the code is fine and I have a file in my template name content-page.php
here is the code of my content-page

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <h1 class="entry-title"><?php the_title(); ?></h1>
    </header><!-- .entry-header -->

    <div class="entry-content">
        <?php the_content(); ?>
        <?php
            wp_link_pages( array(
                'before' => '<div class="page-links">' . __( 'Pages:', 'unite' ),
                'after'  => '</div>',
            ) );

            edit_post_link( __( 'Edit', 'foodgrower' ), '<span class="edit-link">', '</span>' );
        ?>
    </div><!-- .entry-content -->

</article><!-- #post-## -->

I don’t know if I miss something about the setup or query on it. Here’s I really want to displays. I only want to display (the title of the post), but now it displays the content-page.php. I don’t get it also why it appears in my page. I didn’t call the content-page.php to display in my page

Read more here: how to customize post in wordpress?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: