WordPress.org

Ready to get started?Download WordPress

Forums

sidebar code working on index but not on single template (33 posts)

  1. poultryfarm
    Member
    Posted 9 years ago #

    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; ?>'

  2. Kafkaesqui

    Posted 9 years ago #

    It would help a great deal to know what theme you're using, and barring that, have a link to your site.

  3. poultryfarm
    Member
    Posted 9 years ago #

    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.

  4. poultryfarm
    Member
    Posted 9 years ago #

    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?

  5. poultryfarm
    Member
    Posted 9 years ago #

    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.

  6. poultryfarm
    Member
    Posted 9 years ago #

    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.

  7. oriecat
    Member
    Posted 9 years ago #

    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...)

  8. poultryfarm
    Member
    Posted 9 years ago #


  9. poultryfarm
    Member
    Posted 9 years ago #

    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; ?>

  10. oriecat
    Member
    Posted 9 years ago #

    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.

  11. poultryfarm
    Member
    Posted 9 years ago #

    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.

  12. oriecat
    Member
    Posted 9 years ago #

    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

  13. moshu
    Member
    Posted 9 years ago #

    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

  14. Arlo
    Member
    Posted 9 years ago #

    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.

  15. oriecat
    Member
    Posted 9 years ago #

    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... :)

  16. poultryfarm
    Member
    Posted 9 years ago #

    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.

  17. poultryfarm
    Member
    Posted 9 years ago #

    sorry for the confusion. the rest of the "content" isn't there because i am really trying to isolate this problem. so yes i took out the content in the main areas, i.e. it's normal that there is a lot of white space. agaiin I just wanted to bare down the code to isolate this problem to make sure it wasn't anything else that was messing it up.

  18. poultryfarm
    Member
    Posted 9 years ago #

    moshu, those are exactly the links you should be seeing! those are the project names i described above. when you click on those you get to the project page where the same list of project names should appear, but for some reason it's only working correctly on the index page.

  19. poultryfarm
    Member
    Posted 9 years ago #

    arlo, thanks for the link. But, i'm not using any coppermine plugin code. the sidebar code really only consists of the code i mentioned above�again i'm really trying to isolate this problem so i've stripped everything else out. I've tried with all plugins off as well, same problem.

  20. moshu
    Member
    Posted 9 years ago #

    When I click on any of those links - they all disappear... and in the middle of the screen there is a tiny "test" text.
    Which theme did you start off when building your theme? Is there any if statement in your header.php template?

  21. oriecat
    Member
    Posted 9 years ago #

    Ah ok, sorry for the confusion! :) As I said above, I am only seeing one of the items, due to the page not scrolling up high enough. As for why they aren't showing... do you have a single.php and does it include a call to get the sidebar? Are those just recent posts? Why not just use a Recent Post plugin?

  22. Joni
    Member
    Posted 9 years ago #

    PF, I am using Firefox on a Windoze box. Here are the results when I click on the links from your main page:

    # avery --> blank menu area
    # beirut --> blank menu area
    # amy lipton gallery --> Truncated link that says "GALLERY"
    # the london project --> Truncated link that says "PROJECT"

    So it halfway links to two of them. What should be happening, if I understand you correctly, is that if you click on ANY of the links, they should ALL still appear on the sidebar.

  23. poultryfarm
    Member
    Posted 9 years ago #

    jonimueller,
    yes you understand me correctly, all of the link should still appear on the sidebar. the basic idea is that the project title that you are currently viewing will be highlighted in a different color (or underlined, styled differently from the rest) than the rest of the project titles. but all should still be visible and clickable.
    interesing that you get different results than i do. i've tried on both a mac with safari + firefox and on windows using firefox and get the same results:
    # avery --> avery
    # beirut --> beirut
    # amy lipton gallery --> amy lipton gallery
    # the london project --> the london project

  24. poultryfarm
    Member
    Posted 9 years ago #

    moshu,
    sounds like you are experiencing the problem. the titles should still be listed on the right sidebar just like they are on the index page. the "test" that appears is good and is just a filler for some content for that project.
    I really started with a clean slate and pulled and inserted code based on the articles in the codex and at times from code from the default theme. but all in all there is not much php in my theme yet because i've really just been trying to get this part to work!

  25. Joni
    Member
    Posted 9 years ago #

    What resolution is your monitor? (I am using standard 1024x768.) I'm wondering why the last two links I listed were truncated. I mean, I think the amy lipton gallery link should SAY amy lipton gallery, not "GALLERY." Same for the London Project. Weird.

  26. moshu
    Member
    Posted 9 years ago #

    code from the default theme

    That's exactly why I was asking this question :)
    That theme has a lot of if-stuff in the header; like: if single do not show the sidebar...

  27. poultryfarm
    Member
    Posted 9 years ago #

    - no if statement in my header.php
    - my single.php is exactly the same as my index.php (thus my confusion as to why it is displaying differently).
    - i'm not using a recent post plugin because i want to exlude certain categories from this list. for example i have a news section (as well as other categories) that should not be a part of this project list. But i'm certainly open to using a plugin if it will help me achieve this. perhaps I am going about this in a backwards way? i don't think so though.

  28. Joni
    Member
    Posted 9 years ago #

    Okay, I changed my monitor resolution to 1280x960 and MORE LINKS appeared above the ones already there. And the London and Amy Lipton links were NOT truncated any longer. They each only link to themselves. But that is some headway. Odd nonetheless.

  29. poultryfarm
    Member
    Posted 9 years ago #

    my mac is at 1280 x 854
    and my pc is at 1680 x 1050
    yes strange that it truncated the names, but good to know, that will certainly not be acceptable for people with smaller screens. you think that is the problem? but the css should still display normal and you would need to scroll. i don't see why anything would be truncated because of a smaller screen.

  30. Joni
    Member
    Posted 9 years ago #

    If your single.php is the same, why not just use the main template. You don't NEED to have a separate template for individual posts. Try deleting it (or renaming it without the *.php extension so WP can't find it) and see if that makes a difference. Because then, you'd be running the indiv. entries off the main template, which you know already works fine.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags