views:

40

answers:

1

Alrighty, I've got another little bit of code that I'm wrestling through. I'm building a conditional sidebar. The goal is to only show blog related stuff when posts in the "blog" category are being viewed. I've got part of it working, but the part where I'm trying to bring in an RSS feed of the category into the sidebar to show as recent posts. It doesn't work, and since I'm a php newb I'm not entirely sure why. Any suggestions or pointers are much appreciated. I'll post the problem section first, and then the entire php file second, so you all can see the context for the section that I'm having issues with.

Problem Section:

echo '<div class="panel iq-news">';
                echo '<h4><span><a href="/category/blog/feed"><img src="/wp-content/themes/iq/images/rss-icon.gif" alt="Subscribe to our feed"/></a></span>IQNavigator Blog</h4>';
    <?php
    query_posts('category_name=Blog&showposts=2');
    if (have_posts()) : ?>      
                echo '<ul>';
        <?php while (have_posts()) : the_post(); ?>
                echo '<li><a href="<?php the_permalink();?>"><?php the_title();?> </a></li>';
        <?php endwhile;?>
                echo '</ul>';
    <?php endif;?>
                echo '<div class="twitter">';
                echo '<p id="twitter-updates">';
            <?php twitter_updates();?>
                echo '</p>';
                echo '<p class="text-center"><a href="http://twitter.com/iqnavigator"&gt;Follow us on twitter</a></p>';
                echo '</div>';

                echo '</div>';

The whole darn long statement, for context reasons:

        <div class="sidebar">
        <?php
        if (!is_search() && !is_page('Our Clients') && !is_archive()){
            if($post->post_parent) {
                $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=1&exclude=85,87,89,181,97,184");
            }
            else {
                $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1&exclude=85,87,89,181,97,184");
            }
            if ($children) { ?>
        <div class="panel links subnav">
            <h3>In This Section</h3>
            <ul class="subnav">
                <?php echo $children; ?>
            </ul>
            <p>&nbsp;</p>
        </div>
        <?php 
            }
        }
        if(is_page('Our Clients') || in_category('Our Clients') || is_category('Our Clients'))
        {
            echo '<div class="panel links subnav">';
            echo '<h3>In This Section</h3>';
            echo '<ul class="subnav">';
            wp_list_categories('child_of=21&title_li=');
            echo '</ul>';
            echo '<p>&nbsp;</p>';
            echo '</div>';

        }

        else if  (in_category('Blog'))
                {
                                    //PUT YOUR CODE HERE                        
                                    // echo get_page_content(34);                                            
                echo '<div class="panel featured-resource">';
                echo '<h4>Blog Contributors</h4>';
                echo '<ul class"subnav">';
                echo '<li><a href="/company/executive-team/john-f-martin/">John Martin</a></li>';
                echo '<li><a href="/company/executive-team/kieran-brady/">Kieran Brady</a></li>';
                echo '<li><a href="/company/executive-team/art-knapp/">Art Knapp</a></li>';
                echo '</ul>';
                echo '</div>';

                echo '<div class="panel iq-news">';
                echo '<h4><span><a href="/category/blog/feed"><img src="/wp-content/themes/iq/images/rss-icon.gif" alt="Subscribe to our feed"/></a></span>IQNavigator Blog</h4>';
    <?php
    query_posts('category_name=Blog&showposts=2');
    if (have_posts()) : ?>      
                echo '<ul>';
        <?php while (have_posts()) : the_post(); ?>
                echo '<li><a href="<?php the_permalink();?>"><?php the_title();?> </a></li>';
        <?php endwhile;?>
                echo '</ul>';
    <?php endif;?>
                echo '<div class="twitter">';
                echo '<p id="twitter-updates">';
            <?php twitter_updates();?>
                echo '</p>';
                echo '<p class="text-center"><a href="http://twitter.com/iqnavigator"&gt;Follow us on twitter</a></p>';
                echo '</div>';

                echo '</div>';


                                    //END CODE HERE                 

}

        if (!is_page('Resources'))
                    {


        ?>
        <div class="panel featured-resource">
            <h4>Featured Resource</h4>
            <div class="embed">
                <?php
                $custom_fields = get_post_custom();
                $featured_video_code = $custom_fields['Featured Video Code'];
                if($featured_video_code)
                {
                    foreach ( $featured_video_code as $key => $value )
                    {
                        $the_code = $value;
                    }
                    $featured_video_link = $custom_fields['Featured Video Link'];
                    foreach ( $featured_video_link as $key => $value )
                    {
                       $the_link = $value;
                    }   
                    $featured_video_text = $custom_fields['Featured Video Text'];
                    foreach ( $featured_video_text as $key => $value )
                    {
                        $the_text = $value;
                    }
                    if($the_code)
                    {
                        echo $the_code;
                    }
                    if($the_text)
                    {
                        echo '<ul>';
                        echo '<li>';
                        if($the_link)
                        {
                            echo '<a href="' . $the_link . '" class="video" target="_blank">' . $the_text . '</a>';
                        }
                        else 
                        {
                            echo $the_text;

                                                                                    }
                        echo '</li>';
                        echo '</ul>';

                    }
                }

                ?>  


+ Visit Resource Center

        <div class="clr"></div>
        <div class="blue-bars">
            <a href="<?php bloginfo('template_directory');?>/more-info.php" class="more-info" rel="facebox">Request More Info</a>
            <a href="<?php bloginfo('template_directory');?>/resource-form.php?id=701000000009E" class="view-demos" rel="facebox">Schedule a Demo</a>
        </div>
    </div>      
    <div id="content">
+1  A: 

What exactly doesn't work with the feed? If it's the URL, try this (using http://codex.wordpress.org/Template_Tags/bloginfo) :

echo '<h4><span><a href="<?php bloginfo('url'); ?>/category/blog/feed/">
<img src="/wp-content/themes/iq/images/rss-icon.gif" alt="Subscribe to our feed"/></a>

And if you're trying to list posts in the sidebar, it's better to use a new query, which can be used more than once (in a sidebar, page or post) and won't conflict with the main WP loop, i.e.:

  <?php $my_query = new WP_Query('category_name=mycategory&showposts=2'); ?>
  <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
  <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
  <?php the_title(); ?></a><?php endwhile; ?>
songdogtech
that's much better and more concise than what I was using. I'm going to ask a (probably) stupid follow up question: can I call $my_query anything or does it need to be something specific like $query_posts?
poindexter
disregard; I figured that part out... :)
poindexter
In the end, what was wrong? Did that work? If so, accept the answer: stackoverflow.com/faq
songdogtech
it did work; I did not know how to accept an answer initially, but I have now. Thank you!
poindexter