dongzhilian0188 2010-04-30 16:18
浏览 45
已采纳

PHP语句,HTML和RSS

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">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">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条回答 默认 最新

  • duanliushua5026 2010-04-30 16:50
    关注

    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; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路