WordPress.org

Support

Support » How-To and Troubleshooting » sidebar code working on index but not on single template

sidebar code working on index but not on single template

  • Hello,

    I am trying to get a list of posts from a certain category to display in my sidebar. I have followed all of the previous discussions and the examples in the codex. It works great on my index page, but when i go to a single entry the sidebar suddenly doesn’t list them. For testing purposes I have made my single.php have exactly the same code as my index.php. Any ideas why it would work in one and not the other?
    currently it is a loop within a loop. perhaps this is not necessary.

    here are the various codes i’ve tried in my sidebar, both work on the index page, but not on the single.php:
    1.
    ‘<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php query_posts(‘category_name=projects&showposts=27’); ?>
    <?php while (have_posts()) : the_post(); ?>
    “><?php the_title(); echo “
    “; ?>

    <?php endwhile;?>
    <?php endwhile; else: ?>
    sorry, no projects entered yet.
    <?php endif; ?>’
    2.
    ‘<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( in_category(‘2’) ) { ?>
    “><?php the_title(); echo “
    “; ?>

    <?php } else { ?>
    echo “tart”
    <?php } ?>
    <?php endif; ?>’

Viewing 15 replies - 1 through 15 (of 32 total)
  • It would help a great deal to know what theme you’re using, and barring that, have a link to your site.

    I am on WP 1.5.1.3 and I am building my own theme from scratch. You can see what I have here:
    http://www.stanallenarchitect.com/lab/

    The projects show up on the right hand side fine on the index page, but when you click on one of the projects to get to a single page you’ll see: “Sorry, no projects entered yet.” Which, as the code I included above suggests that it is not finding any projects in category “projects” yet on the index page it does.
    Let me know if there is anything I may clarify. Thank you in advance for your help.

    if any php experts out there (or others) can help me with this I would be really grateful. The code on the index and single template are exactly the same… so why would it display differently? is there some php difference that i am not taking into consideration?

    I’ve been reading up on php + wordpress and feel pretty comfortable with both. But I’m stumped here! playing with this for over a week and still no go. I’ve also turned off all of my plugins. I am sorry to keep asking, but I’m at the last of my resources and need to get this to work. Nobody can help me out?
    Please take a look, thank you.

    I posted this almost one month ago, and haven’t recieved any replies. Although I have been toying with this endlessly I still haven’t gotten it to work. I’m really getting desperate for some help. Please if anyone can offer a hand I would very grateful. Thank you.

    I’m not seeing any WP information in your link above. Have you changed it or deleted it? Have you tried just going back to the default,classic or some other theme, and then changing your style from there, instead of starting from scratch (unless I misunderstood what you said above…)

    oriecat: thank you for your reply. I’m not sure I follow you though. What exactly is not clear about my posts above? so I may better explain the problem. What do you mean you don’t see any WP information? I’m not having any css “style” problems, rather WP php problems. When you click on the link http://www.stanallenarchitect.com/lab/ you’ll see a list of projects on the sidebar to the right (this is good the code is working on the index page). If you click on one of the projects however, you will see that the sidebar now only contains the current project name (it should contain the same list of projects as on the index page). It is the same code in the index page as in the project page… so why is it displaying differently. The code that I am currently using in my sidebar is this:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php query_posts('cat=2,3,4,5,6,7'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <li id="project-<?php the_id(); ?>"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile;?>
    <?php endwhile; else: ?>
    <li id="project-<?php the_id(); ?>"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endif; ?>

    When I click on your link, I am only seeing a white page, with a bunch of light blue lines dividing it into sections. I am seeing NO content. I checked in Firefox and IE, same thing, except the lines are different.

    Whoa! that’s strange. I think maybe it was just to light a grey on your screen. I’ve now changed it to stark red. Let me know if you see them now. sorry about that.

    Nope, still nothing. I thought it might be a color issue, so I tried to highlight the text so I would see it in reverse, but there’s nothing there to highlight. And if I view the source code, there’s no content there either.

    http://moltenwords.net/temp/lab.jpg

    I cannot see any content either. Just these links in the far right upper corner. (FF1.04.)
    # avery
    # beirut
    # amy lipton gallery
    # the london project

    I had a somewhat similar problem, that I traced to some funky external code I had put in my sidebar: http://wordpress.org/support/topic/39812

    This may or may not apply in your case, but it’s worth a look.

    Oh that’s interesting. I was only seeing The London Project, but if I go full screen I can see the others that moshu did. The page must not be scrolling enough vertically. Aside from missing everything else… 🙂

    Ok, I’ve checked on my mac and on my pc (firefox) and both display fine. Looking at your screenshot it looks like the text is thereâ€?i can see a bit of the ‘t’â€?just scroll to the right more. Are you viewing on a smaller-sized screen? If you scroll to the right you should see the sidebar.

Viewing 15 replies - 1 through 15 (of 32 total)
  • The topic ‘sidebar code working on index but not on single template’ is closed to new replies.