Wordpress post page loop acting strange - php

I am having an issue with my Wordpress post loop where if I add or update a post it decides to kill one odd and it disappears? Has any had this issue before?
<?php query_posts('posts_per_page=4&cat=3'); while(have_posts()) : the_post(); ?>
<div class="eventPostOuter">
<div class="eventPost">
<span class="eventsImage">
<?php the_post_thumbnail( array(200,200) ); ?></span>
<h3><?php the_title(); ?></h3>
<span style="padding-bottom: 40px;" class="exerpt"><p><?php echo substr(get_the_excerpt(), 0,200); ?> [...]</p></span>
<!--<span class="excerpt" style="padding-top: 20px;"><p><a class="excerptLink" href="<?php the_permalink(); ?>">Read full article</a></p></span>-->
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
That is my code, perhaps I have made an error in there somewhere? I am unable to see what the issue is and it has only just begun doing it...

Ok, I fixed the issue which is so strange, I changed the character limit from 200 to 180 and all of the posts show perfectly. :S

Related

Issue with ACF fields showing up in WordPress template

Okay, I am having the most bizarre issue ever. I have a custom home page template for a WordPress site I am working on.
You can see a screenshot of how I have my ACF fields for this template setup on the backend here.
The issue I am having is that when I try to display the field
<img src="<?php the_field('slide_1_thumb'); ?>" alt="" />
the image doesn't show up at all. I have the Return Value set to 'Image URL', and the odd thing is that it shows the images for
<?php the_field('slide_1'); ?>
just fine with no issues at all.
I'm not sure what I am doing wrong here, but there are no spelling errors at all, for some reason those slide_1_thumb images won't show up. I want to think this is one of those Occam's Razor type of situations where I missed something so simple, but I've gone over this a million times with no luck.
Below you will find a copy of the PHP code for my home-page.php template.
<?php
/**
* Template Name: Home Page
*
* A custom template for the home page.
*
* The "Template Name:" bit above allows this to be selectable
* from a dropdown menu on the edit page screen.
*/
get_header(); ?>
<div id="slideshow-container">
<div id="slideshow" class="slideshow pcfcu-theme">
<div class="slideshow-img" style="background-image: url(<?php the_field('slide_1'); ?>);">
<div class="slideshow-img-inner">
<div class="slideshow-img-text">
<h1><?php the_field('slide_1_title'); ?></h1>
<p><?php the_field('slide_1_description'); ?></p>
</div>
</div>
</div>
<div class="slideshow-img" style="background-image: url(<?php the_field('slide_2'); ?>);">
<div class="slideshow-img-inner">
<div class="slideshow-img-text">
<h1><?php the_field('slide_2_title'); ?></h1>
<p><?php the_field('slide_2_description'); ?></p>
</div>
</div>
</div>
<div class="slideshow-img" style="background-image: url(<?php the_field('slide_3'); ?>);">
<div class="slideshow-img-inner">
<div class="slideshow-img-text">
<h1><?php the_field('slide_3_title'); ?></h1>
<p><?php the_field('slide_3_description'); ?></p>
</div>
</div>
</div>
</div>
</div>
<div id="content-container">
<div id="content-container-inner">
<div id="recent-blog-entries-container">
<div id="recent-blog-entries">
<header><h1>Recent Blog Entries</h1></header>
<?php $postslist = get_posts('numberposts=2&order=DESC&orderby=date');
foreach ($postslist as $post) : setup_postdata($post);
?>
<h2 class="rbe-title"><?php the_title(); ?></h2>
<p class="rbe-posted-on">Posted on: <?php the_time(get_option('date_format')) ?></p>
<div class="rbe-excerpt"><?php the_excerpt(); ?></div>
<?php endforeach; ?>
</div>
</div>
<div id="features">
<header><h1>Features</h1></header>
<a class="goTo1"><div class="feature-thumb"><img src="<?php the_field('slide_1_thumb'); ?>" alt="" /></div></a>
<a class="goTo2"><div class="feature-thumb"><img src="<?php the_field('slide_2_thumb'); ?>" alt="" /></div></a>
<a class="goTo3"><div class="feature-thumb"><img src="<?php the_field('slide_3_thumb'); ?>" alt="" /></div></a>
</div>
</div>
</div>
<?php get_footer(); ?>
Another strange thing is that if you take one of the working ACF images such as
<?php the_field('slide_1'); ?>
it works perfectly and outputs the image, but when you move it down to the 'Features' section of the code to see if it will work in place of one of those small feature thumbnails, it won't work in that portion of the code. It's almost as if that bottom 'Features' portion of the page has some sort of error, but I don't see any errors at all in my code.
In other words, ALL of this code works perfect up until the very last portion of it with the 'feature' thumbnail images. You can see this live on the website here.
When making a new loop using get_posts(), you should end it with the wp_reset_postdata() function to reset your loop's data back to what it was before the get_posts(). So try this:
<div id="recent-blog-entries">
<header><h1>Recent Blog Entries</h1></header>
<?php $postslist = get_posts('numberposts=2&order=DESC&orderby=date');
foreach ($postslist as $post) : setup_postdata($post); ?>
<h2 class="rbe-title"><?php the_title(); ?></h2>
<p class="rbe-posted-on">Posted on: <?php the_time(get_option('date_format')) ?></p>
<div class="rbe-excerpt"><?php the_excerpt(); ?></div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
</div>
Adding the wp_reset_postdata() after your loop should fix this for you.
Okay, I have NO idea what was going on, but all I had to do to fix this was delete the ACF fields on the backend and then recreate them with the EXACT same names as before. Sure enough that fixed it.
So, while I don't have a conclusive answer as to why this was happening, all I can say is that it must have been some sort of odd glitch.

Wordpress post loop

So im trying to add a function called "latest posts" in a sidebar section.
This is how my code looks like in sidebar.php-file.
<?php
query_posts('category = all');
if (have_posts()) :
while (have_posts()) : ?>
<?php the_post();
the_excerpt(); ?>
<p class="datum2"><?php the_time('Y-m-d'); ?></p>
<p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
<p class="textnyhet2">
</p>
<?php endwhile;
endif;
?>
My problem is, no matter how much I move around in the code I just cant seems to get the correct title/date to appear above the correct post.
Now it's like the post comes first, then right under the post the date and title appears above another incorrect post etc.
Example:
Latest post text
space---->
title/date, (though to the post above)
latest post text
space----->
and continue like that.
Would be grateful if anyone could help me out.
Thanks!
The reason the title/date appears below the post is because that's the way you have specified it to appear. Change
<?php the_post();
the_excerpt(); ?>
<p class="datum2"><?php the_time('Y-m-d'); ?></p>
<p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
<p class="textnyhet2">
</p>
to
<?php the_post(); ?>
<p class="datum2"><?php the_time('Y-m-d'); ?></p>
<p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
<?php the_excerpt(); ?>
<p class="textnyhet2">
</p>
It should display the way you want it.
the_excerpt(); is printing out an excerpt of the post, then the time/title displays. Now it should display the time and title first, then display the excerpt of the post.

Getting the post title in index php in a while loop

I have
<?php while ( have_posts() ) : the_post(); ?>
<div class="boxes-third boxes-first">
<div class="latestthree">
<div class="title">
<?php get_the_title($id); ?> // I am trying to get the post title here but doesn't work
<span class="titlearrow"></span>
</div>
<div class="latestthreeimage">
<a rel="prettyPhoto" title="<?php get_the_title($id); ?>"> /same here
<?php the_post_thumbnail(array(300,133)); ?>
</a></div>
<div class="text">
Here i would like to get the excerpt of the post that is no longer than 25 words
<span class="textarrow"></span>
</div>
</div>
</div>
<?php endwhile; ?>
I am trying to do the above mentioned, but did not worked and on the last one did not find related info. I am using wp 3.7.1. Please help me.
You have used get_the_title() which does not print. To print out the title, add an extra echo:
<?php echo get_the_title(); ?>
Or you can use the_title(), which also prints:
<?php the_title();?>
Try just using,
the_title();
Reference.

php link to another page

im editing a wordpress theme for my own personal website. The page is for a blog, and what is meant to happen is that when you click on the 'read more' or blog title then it will open that blog in the seperate page to read. however when i click these 2 things i get the following message:
Server error The website encountered an error while retrieving
mywebsite/wordpress/?p=20. It may be down for maintenance or
configured incorrectly. Here are some suggestions: Reload this web
page later. HTTP Error 500 (Internal Server Error): An unexpected
condition was encountered while the server was attempting to fulfil
the request.
it was previously working before so i know the code that came with the theme worked. heres the code:
<div class="box">
<?php while ( have_posts() ) : the_post(); ?>
<article>
<h2><?php the_title(); ?></h2>
<h7>BY LOUIS MOORE ON</h7> <time datetime="<?php the_time( 'Y-m-d' ); ?>" pubdate><?php the_date(); ?> <?php the_time(); ?></time><?php the_content(); ?>
<a href="<?php esc_url( the_permalink() ); ?>"/><h8>READ MORE</a></h8> </br>
</br><div class="h9"></div>
</article></br></br></br>
<?php endwhile; ?>
</div>
im not the gretest at php and i havent really changed it from its original form other than the things such as 'read more' 'by louis moore' the second div and the </br>
There are several errors in the HTML code. Maybe that's the problem.
You may try this:
<div class="box">
<?php while ( have_posts() ) : the_post(); ?>
<article>
<h2> <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?> </h2>
<h7>BY LOUIS MOORE ON</h7>
<time datetime="<?php the_time( 'Y-m-d' ); ?>"> pubdate><?php the_date(); ?> <?php the_time(); ?></time><?php the_content(); ?>
<h8>READ MORE</a></h8>
<br /><br />
<div class="h9"></div>
</article><br /><br /><br />
<?php endwhile; ?>
</div>

php query_posts orderby=random causing css to break

<?php query_posts($query_string . '&orderby=rand') ?>
Hey all,
I've tried to implement the above piece of code into my portfolio page template.php.
http://www.some-things.net/category/work/
It's causing the css to break every so often. Reload it until it breaks and you will see what I mean. It pushes 2 of the portfolioitem blocks to the right a touch and forces the third to drop a line?
<div style="clear:both"></div>
<div class="gallery">
<?php query_posts($query_string . '&orderby=rand') ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="portfolioItem">
<a href="<?php the_permalink() ?>" class="desctitle" title="<?php the_title();?>"><?php the_post_thumbnail(); ?>
<span class="desctitle"><?php the_title(); ?></a>
</span>
</div>
<?php endwhile; ?>
</div>
The error isn't in the random layout code. It's caused by an empty "tile" in your page. here's the source of the offending tile:
<div class="portfolioItem">
<span class="desctitle">Love Jungle</span>
</div>
Notice there's no image.

Categories