I have a problem with my code, somehow. It worked fine before and now it seems that Wordpress does not show the title of the second blog posts (only the first blog post seems to work fine really, whereas the rest is just messed up).
I don't know if this is in an error in my code, or if this is an issue with Wordpress itself.
I can't fix it myself and desperately need help otherwise I have to start the code from scratch again.
This is my index.php file:
<div class="row">
<div class="column left">
<div class="inside-container">
this is the index.php where all the blog posts go
<p></p>
<?php while(have_posts()) {
the_post(); ?>
<h2 class="date_and_time"><?php the_time('F jS, Y'); ?></h2>
<?php the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_content(); ?>
<div class="blog-post"></div>
<?php } ?>
<div class="pagination">
<div style="float: left">
<?php previous_posts_link('<div class="arrowleft"></div> newer posts'); ?>
</div>
<div style="float: right">
<?php next_posts_link('<div class="arrowright"></div>older posts'); ?>
</div>
</div>
</div>
</div>
<div class="column right">
<div class="inside-sidebar">
<?php get_sidebar(); ?>
</div>
</div>
</div>
</div>
And my CSS file:
/* CONTAINER blog posts and sidebar*/
.column {
float: left;
width: 100%
background-color: #ddd;
}
.left {
width: 65%;
padding-bottom: 40px;
background-color: #EFEFEF;
}
.right {
width: 35%;
padding-bottom: 20px;
background-color: #E7E7E7;
}
.row:after {
content: "";
display: table;
clear: both;
}
/* BLOG POST CONTAINER */
.inside-container {
padding: 0px 40px 0px 0px;
}
/* SIDEBAR CONTAINER */
.inside-sidebar {
padding: 0px 0px 0px 40px;
}
/* BLOG POST DATE */
h2.date_and_time {
overflow: hidden;
font-family: sans-serif;
font-size: 11px;
letter-spacing: 2.5px;
text-transform: uppercase;
text-align: center;
font-weight: normal;
}
h2.date_and_time::before,
h2.date_and_time::after {
content: "";
display: inline-block;
height: 1px;
position: relative;
vertical-align: middle;
width: 50%;
background: #000;
}
h2.date_and_time:before {
right: 1em;
margin-left: -50%;
}
h2.date_and_time:after {
left: 1em;
margin-right: -50%;
}
/* BLOG POST TITLE */
h3 {
font-family: serif;
font-size: 25px;
letter-spacing: 1px;
text-transform: uppercase;
text-align: center;
font-weight: normal;
}
/* BLOG POSTS */
.blog-post {
padding-bottom: 40px;
}
I really do not know what went wrong and I can't see the forest for the trees anymore. Also, this is my first time working with .php and Wordpress.
</div>
from your index.php snippet matches no opening<div>
tag. Probably all you need to do is to remove the last</div>
and everything should go back to normal. – leymannx Apr 2 '19 at 20:30the_title()
within the loop should show a title for each post. Perhaps the issue is in your query. I would suggest looking at another theme's structure - normally you never useindex.php
for a homepage template, you usefront-page.php
orhome.php
- and trying a query monitor plugin to see what specific posts WordPress called for. Perhaps your loop is pulling in more than just Post posts - attachments and Pages are also stored in "posts" so it could be you need to update the query to specify post type. – WebElaine Apr 2 '19 at 20:31the_post()
in the loop. First glance, not sure of the impact there but callingthe_post()
should only happen once. After a bit of reading, that is most likely the problem. I'll post an answer. – jdm2112 Apr 2 '19 at 20:57