Forums

[resolved] Theme broken when not logged in (18 posts)

  1. Echo Zoe
    Member
    Posted 4 years ago #

    I can't figure out why, but my theme doesn't work when I'm not logged in. My main site is here, but I have a test site up here that I set up to develop the theme. At the test site, everything works fine. However, at my main site, if I am not logged in to the backend, no content is displayed on the site. It is as if I have no posts or pages at all.

    Does anyone have any idea why that would be?

  2. Ivovic
    Member
    Posted 4 years ago #

    I guess I shouldn't be able to see this then:

    "I also have no idea why that site works just fine, but when I copy the theme over to this site, changing only the category numbers in the code to match the ones for this site, it breaks."

    certainly not a blank page.

    I'm just dying to see you say that you switched themes or something, to get rid of the error, thereby completely invalidating having linked your site at all.

  3. Echo Zoe
    Member
    Posted 4 years ago #

    Well, I do want to keep the site alive while I find a solution to the problem, so the old theme is there for now.

    I suppose the best way to show what it is doing while keeping the site alive is with a screenshot.

    Also, if it helps to see the theme itself, you can download it here.

    Deactivating plugins has no effect on things.

  4. Ivovic
    Member
    Posted 4 years ago #

    that screenshot shows the 404 message... it's making me wonder whether you have indeed changed your category IDs correctly when switching from your dev server to your live site.

    without being able to play with the site itself, I can't really confirm anything though. A screenshot is only a touch less useless than nothing at all.

  5. Echo Zoe
    Member
    Posted 4 years ago #

    That's not the 404 page, the maroon title bars don't show up on a 404.

    Also, even if I had the wrong category IDs (despite re-checking many times), at least the "Blog" portion should show something, as the categories are defined in the negative (cat=-54,-56), so it should show everything in categories that aren't #54 or #56. I am certain that the category IDs are correct because when I am logged in to the site as administrator, the site looks as it was designed to look. The problem is that I can't exactly allow all of my visitors to log in as administrator in order to see the site correctly.

    I just installed a user-level theme switcher to allow me to keep the site live with the old theme while still being able to provide a link to the broken theme. You can access the site via the broken theme here.

  6. Ivovic
    Member
    Posted 4 years ago #

    well, even cookied your posts and category pages show up....

    http://www.echozoe.com/?cat=2 while cookied, works perfectly... so whatever the problem is, seems to be localised to your index.php

    ...

    after I open up your theme zip to look at your index.php, I find an interesting yet useless little index.html sitting there as well.

    any chance that's causing the issue? it seems to have your front page code in it, for some odd reason.

    Seems odd for that to be loaded from the theme directory - but I don't see anything wrong with your index.php - so I can only assume it is.

  7. Echo Zoe
    Member
    Posted 4 years ago #

    You're right, that file is useless, and I don't know why it was there at all. I deleted it from the site's folder for that theme, but it didn't help.

    Thanks for your input so far, I really appreciate your willingness to help.

  8. Ivovic
    Member
    Posted 4 years ago #

    ahh, I think I might have found your problem on index.php.

    you have multiple loops, and though they are structured correctly, you keep prefacing the queries with "<?php if (have_posts()) : ?>"

    Unfortunately you don't really have_posts until you do your query... that have_posts is there on pages which don't create their own custom queries. I bet if you remove that conditional around every single additional loop you have, you'll find your site works.

    Just guessing, as I've not actually loaded up your theme here, but it seems logical.

    you can put that conditional in once... around everything... but not this many times - and certainly not before each query.

  9. Ivovic
    Member
    Posted 4 years ago #

    I want to add... particularly because you're doing it incorrectly... here's the deal:

    This is what you have:

    <?php if (have_posts()) : ?>
    <?php $my_query = new WP_Query('cat=10&showposts=5');
    while ($my_query->have_posts()) : $my_query->the_post(); ?>

    can you see that have_posts is already being applied in the while loop?.. but to the custom query - not just on its own. maybe what you want is this:

    <?php $my_query = new WP_Query('cat=10&showposts=5');
    if ($my_query->have_posts()) while ($my_query->have_posts()) : $my_query->the_post(); ?>

    obviously then you'll need to close the if statement at the end - but notice the query runs first, then you check have_posts.

    by the way, it actually really helped that you let me play with your blog using the right theme, because that way I was able to focus on one file only - otherwise I'd have had to assume that it was happening on all pages - which it was not, just on the index.

  10. Echo Zoe
    Member
    Posted 4 years ago #

    I am very much a novice when it comes to the php aspects of developing a template, but that seems to make sense. I must not yet be understanding it fully though because I tweaked it and my tweaks yield nothing at all - just a blank white page.

    Here is what I changed the index.php file to:

    <?php get_header(); ?>
      <div id="container">
    
    	    <div id="leftnav">
    	  <?php get_sidebar(); ?>
    		</div>
        <div id="rightnav">
    	  <?php include (TEMPLATEPATH . '/sidebar2.php'); ?>
        </div>
    
        <div id="content">
    
    <img src="/wp-content/themes/ZoeLines/img/ez-central-header.png">
    
     	<?php $my_query = query_posts('page_id=2184'); if ($my_query->have_posts()) while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<div class="post" id="post-<?php the_ID(); ?>">
    				<div class="entry">
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div>
    			</div>
    
    		<?php endwhile; else: ?>
    
     Sorry, we goofed.
    
    	<?php endif; ?>
    
    <img src="/wp-content/themes/ZoeLines/img/ez-podcast-header.png">
    
     	<?php $my_query = new WP_Query('cat=54&showposts=3'); if ($my_query->have_posts()) while ($my_query->have_posts()) : $my_query->the_post(); ?>
    				<div class="entry">
    				<h6><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_time('F Y') ?> - <?php the_title(); ?></a></h6>
    				</div>
    
    		<?php endwhile; else: ?>
    
     There are no podcasts at this time.
    
    	<?php endif; ?> 
    
    <img src="/wp-content/themes/ZoeLines/img/ez-articles-section-header.png">
    
     	<?php $my_query = new WP_Query('cat=56&showposts=5'); if ($my_query->have_posts()) while ($my_query->have_posts()) : $my_query->the_post(); ?>
    				<div class="entry">
    				<h6><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_time('F j, Y') ?> - <?php the_title(); ?></a></h6> <?php the_excerpt(); ?>
    				</div>
    
    		<?php endwhile; else: ?>
    
     There are no articles at this time.
    
    	<?php endif; ?> 
    
    <a name="blog"></a><img src="/wp-content/themes/ZoeLines/img/ez-blog-header.png">
    			<?php if (have_posts()) : ?>
    			<?php $my_query = new WP_Query('cat=-54,-56');
    			while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    		<div class="post" id="post-<?php the_ID(); ?>">
    
    			<div class="date"> <?php the_time('F') ?>
    				<?php the_time('d, Y') ?> </div>
    				<h3 class="posttitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
    
    				<div class="entry">
    					<?php the_content('Continue Reading &raquo;'); ?>
    					<hr align=center noshade size=2 color=#990000>
    
    				</div>
    
    			</div>
    				<p class="postmetadata">Posted in <?php the_category(', ') ?>
    				<a href="<?php comments_link(); ?>"><?php comments_number('Write a Comment', '1 Comment', '% Comments'); ?></a>
    
    		<?php endwhile; ?>
    
    			<div class="navigation">
    				<div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
    				<div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
    			</div>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.
    
    		<?php include (TEMPLATEPATH . "/searchform.php"); ?>
    
    	<?php endif; ?>
    
    </div>
    
    <?php get_footer(); ?>
    </div>
    </body>
    </html>

    It also still baffles me why the same file seems to work fine on the development site.

    I'm glad you prodded me to think to set up the user-switchable themes. Not only because it helps illustrate what's going on so well but because it helps me to troubleshoot without setting a (potentially) broken theme as the default. This should be built into a stock installation of WordPress!

  11. Ivovic
    Member
    Posted 4 years ago #

    I've been up all night, and my eyes are bleeding, so I don't know about your blank page issues - but I can see you STILL have at least one more instance of

    <?php if (have_posts()) : ?>

    before query_posts on your page.

    You'll really need to pull that apart and put it back together again.

    Can I suggest you keep that file aside for the moment and make yourself a new index.php by pasting in what you want to do, chunk by chunk... making sure each smaller section works fine before throwing in another.

    I also suggest leaving out the have_posts stuff from everywhere except the WHILE loop for now. It's not really necessary if you have posts to display. Nice to put back eventually - but don't confuse yourself with it now.

  12. Echo Zoe
    Member
    Posted 4 years ago #

    I am, like I mentioned, a total novice when it comes to php (and certainly no expert at css and html), but I have gone back and read up on the Loop, and everything I find suggests that I need to have <?php if (have_posts()) : ?> at the beginning of each loop in my index page.

    I've tried rewriting the loops from scratch, using your suggestions, as well as examples from other multiple-loop tutorials and everything has turned out breaking completely.

    I am surprised I get this to work at all, to be honest; but I am utterly baffled as to why it works well at the development site and when logged in to the real site but doesn't work at the real site when not logged in.

    (BTW, killarair is just a forum spammer)

  13. whooami
    Member
    Posted 4 years ago #

    (BTW, killarair is just a forum spammer)

    I know, I flagged another spammy thread too ..

  14. Echo Zoe
    Member
    Posted 4 years ago #

    I cut the main site/theme down to one loop for the time being, and that works fine. I still hope to get the multi-loop design working though.

  15. Ivovic
    Member
    Posted 4 years ago #

    only the first loop has "if (have_posts())" before it. That's because there's no "query_posts" to follow the first loop.

    http://codex.wordpress.org/The_Loop

    read the instructions with care... paying particular attention to the section "Multiple Loops Example 1" and onwards.

    wherever you see query_posts you will not see "if (have_posts())" directly before it.

    I'll try to make this as clear as I possibly can, once more. Until you query the database for posts, you can't possibly have any. The first loop runs based on the default query which isn't specified in your template. All subsequent queries are your custom effort, and must go BEFORE you check whether you have any posts or not.

    You will of course interpret the documentation any way you like, but first ask yourself which one of us has the problem.

    I'm sorry if that sounds harsh, but repetition will do that to a guy.

  16. Echo Zoe
    Member
    Posted 4 years ago #

    I apologize if I am causing frustration. I do appreciate the help.

    The weekend is almost gone and I may not have time to troubleshoot again for a while. I'll go back and pour over it again when I get a chance.

    Text can be a difficult means of communication, as emotions can be improperly communicated. In all sincerity, I do thank you for your help.

  17. Ivovic
    Member
    Posted 4 years ago #

    no, it's my fault... when responding to dozens of threads, sometimes the inevitable banality builds up.

    I apologise.

    Unfortunately I'm not equipped to be recoding your page for you, as I'm just spread too thinly between what I'm trying to do for my own site, and offering what I can, to as many as I can along the way.

    I realise you didn't ask for that - but I wanted you to know that it had crossed my mind in order to bring resolution more quickly for you.

    Ultimately though, cutting your teeth will help you in the long run.

  18. Echo Zoe
    Member
    Posted 4 years ago #

    Ivovic,

    Thanks so much for your persistence and help. With a few extra minutes this morning to take another stab at it, I think I got it working!!

    I haven't had time to pick through it with a fine-toothed comb, but on the surface everything looks great!

    The key was to input: <?php rewind_posts(); ?> at the beginning of the second and each subsequent loop, and remove <?php else: ?> for the same loops.

    Thanks again!!!

Topic Closed

This topic has been closed to new replies.

About this Topic