WordPress.org

Ready to get started?Download WordPress

Forums

sidebar loop either breaks page or doesn't retrieve all of post/page values (1 post)

  1. rocketman1223
    Member
    Posted 5 years ago #

    I want a sidebar pop-up to pull content from portfolio pages and then link to them in the sidebar (a good example would be the "Recent Projects" section on http://www.barbariangroup.com/). To do so, I will need to pull permalink, title, tags and likely a custom field or two. But, all of this is about 2 steps ahead of where I am right now.

    Using the following very basic test query, I'm only able to pull permalink and title. I'm not close to adequate with PHP to figure out my problem and this is my first stab at making significant customizations in WP (despite using it for years). Here's my code:

    <?php $portfolio_posts = new WP_Query('page_id=1156');
    if($portfolio_posts->have_posts()) : while($portfolio_posts->have_posts()) : $portfolio_posts->the_post();
    ?>
      <!-- do stuff -->
    <?php endwhile;
    endif; ?>

    From a different forum, I got the idea to try the following, which does pull the correct content from the page, but it completely ruins all other post queries on the page.

    <?php global $post;
    $myposts = get_posts('page_id=1156');
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>
      <!-- do stuff -->
    <?php endwhile; ?>

    Thanks in advance!

Topic Closed

This topic has been closed to new replies.

About this Topic