• Alright.. I have wordpress set up (only using pages), and I have a sidebar-lef.php and sidebar-right.php. The page structure is sidebar left | content(page content) | sidebar right … I was trying to pull in CPT into my left sidebar. However, when I do, it appears in the content section totally overriding the page content I entered in. I have this in my functions.php:

    <?php
    // Creates Movies post type
    register_post_type('movies', array(
    'label' => 'Movies',
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => array('slug' => 'movies'),
    'query_var' => true,
    'supports' => array(
    'title',
    'editor',
    'excerpt',
    'page-attributes',)
    ) );
    ?>

    And I have this in my sidebar-left.php:

    <div id="sidebar-left">
    <?php query_posts(array('post_type' => array('post', 'movies'))); ?>
    </div>

    Any clue what I am doing wrong

Viewing 6 replies - 1 through 6 (of 6 total)
  • You are not using the results of the query in the sidebar. You probably should use a new WP_Query object and loop through displaying the results. Something like this:

    <div id=”sidebar-left”>
    <?php $movies = new WP_Query(array(‘post_type’ => array(‘post’, ‘movies’)));
    if ($movies->have_posts()) {
    while ($movies->have_posts()) {
    $movies->the_post();
    // display whatever you want from each post
    }
    }
    ?>
    </div>`

    Thread Starter louisstephens

    (@louisstephens)

    Oh ok.. So correct me if I am wrong..

    where you have “display whatever you want”, I could simply put <?php the_title(); ?>
    ?

    I am pretty new to manipulating the post data.

    That is close: you do not need the opening and closing php tags for that particular line.

    Thread Starter louisstephens

    (@louisstephens)

    Thanks vtxyzzy!

    It did work. However, I tried adding

    <h5>the_title();</h5
    <p>the_content();</p>

    and it broke entirely. It seems the only thing I got working was just

    the_title(); which displayed everything in the post..

    You are mixing HTML and PHP. PHP needs to be enclosed in php tags – HTML cannot be enclosed. So, you have to watch where you use the tags.

    <div id="sidebar-left">
    <?php $movies = new WP_Query(array('post_type' => array('post', 'movies')));
    if ($movies->have_posts()) {
       while ($movies->have_posts()) {
          $movies->the_post(); ?>
          <h5><?php the_title(); ?></h5>
          <p><?php the_content(); ?></p>
       }
    }
    ?>
    </div>
    Thread Starter louisstephens

    (@louisstephens)

    Ah.. That was a big mess up on my behalf.. Thanks vtxyzzy.. . I appreciate the help and your patience with me.

    With your code

    <div id="sidebar-left">
    <?php $vids = new WP_Query(array('post_type' => array('post', 'vids')));
    if ($vids->have_posts()) {
    while ($vids->have_posts()) {
    $vids->the_post();?>
    <h1> <?php the_title(); ?></h1>
    the_content();
    }
    }
    ?>
    </div>

    I noticed that the last closing ?> is not getting picked up. Well, in coda the color highlighting is not seeing it as a closing tag and wordpress is breaking again. I understand what you are saying though by having to encapsulate the_content(); in php tags.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Post Type >.’ is closed to new replies.