0

I've been trying to figure out a little problem since yesterday. I made a CPT that is supposed to be posts that are styled and use the same template as regular posts in wordpress.

When I bring up a CPT post for this, the page's layout is messed up.

Both a regular post and a CPT post query the single.php file, so from what I've learned, they should both look identical, except they do not.

I went into the console and found that the divs were incorrect to start with.

This is what I saw for a regular post calling single.php:

A Regular Post

And this is what I saw for a CPT post calling the same single.php file: CPT Post

As you can see, the sidebar-container is supposed to be nested inside "div=container > div= inner-box". But in the CPT post the sidebar-container is outside of the "div=container".

I have gone through single and content php files to see if I placed any extra divs and such. Like I said, the regular post is styled perfectly and everything works fine on it.

I am making a content-cptname.php file and a single-cptname.php file so I can work on the problem without interfering with the single.php and content file I already have.

I would like to know what I am possibly doing wrong here, what is potentially causing this problem since these two posts are supposed to be identical.

Thanks!

Please let me know if you want to see anymore of the site, like the functions code for the CPT.

  • This seems very localized and mostly about HTML errors which is pretty much off-topic here. Is this a child theme or a custom singular theme? What template files do you have? Have you ran your website through a validator such as W3C? – Howdy_McGee Jan 20 '16 at 16:05
  • It's a custom singular theme. I only have the barebones template files in place. I will run through a W3C validator in a moment. I was just wondering if this was a particular problem people encountered. Since it isn't, I will work through it knowing that I probably went wrong somewhere. Thanks – Nimara Jan 20 '16 at 16:11
  • Very strange. If you get stuck, post a new question with the specifics. A code editor with brace highlighting will track down any unclosed brackets. – jdm2112 Jan 20 '16 at 16:36
  • I slapped on another barebones theme that I know works. It shows the posts nicely and perfectly. I then copied those content.php and single.php files back to my current theme. The problem still persisted. So it is not on based from the content.php and single.php. I am looking into the header.php and other templates next. At least now I know it really did have to do with something within my code. I thought I went through it with a fine tooth comb (in Sublime) yesterday but I must have overlooked something again. What is weird is that it would work nicely with one post but not all posts. – Nimara Jan 20 '16 at 17:20
  • Is there anyway I can see EVERY template that is being called on when a page is being loaded? I know I can see the initial template like single.php through the Debug, but maybe there's something else I'm missing. – Nimara Jan 20 '16 at 17:21
0

So it took me nearly 3 days to figure out what was wrong but I narrowed it down after a very exhaustive set of tests. I figured I'd post the answer for my own reference and if, for any reason, someone made the same mistake as I did.

The question I kept asking was "What is different between these two posts?".

The answer I failed to keep giving myself was "One has tags and one does not".

Here was the problem code in the content.php file:

<?php if ( has_category() ) : ?>
    <div class="category-links">Category: <?php the_category( ', ' ); ?>
<?php endif; ?>
</div>
<?php if ( has_tag() ) : ?>
    <div class="tag-links"> <?php the_tags( 'Tagged: ', ', ', '<br />' ); ?> 
<?php endif; ?>
</div>

All the posts had categories, but the problem pages did not have tags. The resulting visual output was caused by improperly placed divs that I kept overlooking. When there was no tag, there was an extra causing the overall container to close prematurely, excluding the sidebar that needed to be inside.

Just another case of overlooked simple answers and another chapter in my road to learning web development.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.