Wordpress post loop - php

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.

Related

Taxonomy Term loop which display all the posts of a term, not only one

I have a problem, I have a taxonomy named categories, and terms in it. On the page of this taxonomy, I would like to display each post of the term. But with this loop that I made, only the first post of the good term is displaying on the page. So I don't know why my loop doesn't display every posts of the term.
Here is my code :
<?php $term=get_term_by('slug',get_query_var('term'),get_query_var('taxonomy')); ?>
<?php if (have_posts()): while(have_posts()): the_post(); ?>
<div class="article-menu a-m-sp">
<a href="<?php the_permalink(); ?>">
<span class="rollover r2"> </span>
<?php the_post_thumbnail(array(226,150)); ?>
</a>
<div class="right p-special">
<h2 class="h2-article-menu h2-ma"><?php the_title(); ?></h2>
<p class="date"><?php pll_e('Publié le ') ?> <?php the_time('j F Y'); ?></p>
<?php the_excerpt(); ?>
<?php pll_e('Lire la suite') ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</article>
<?php get_footer(); ?>
Thank you for your help. I'm a wordpress beginner.

Wordpress post page loop acting strange

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

featured post same as post content

I have a wordpress site I am creating.
on the post pages, I have text widget with PHP allowed, where I have a custom loop:
<?php $my_query2 = new WP_Query("showposts=1&cat=9,10,11,18,19&orderby=rand"); ?>
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>">
<div class="home-widget-thumb">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('home-thumb');
}
?>
</div>
<h2><?php the_title(); ?></h2></a>
<div class="body">
<?php echo get_the_excerpt(); ?>
</div><!--body-->
</br>
<span class="more-link">
[more]
</span>
<?php endwhile; ?>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
For some reason, whatever blog post you are on is the same as in the loop I created.
See an example here:
http://counselingandtraining.com/play-therapy/
The loop for the post is not modified.
Can anyone tell me why this is happening?
Let me know if I can provide further info.
Thanks in advance for your time.
Chris
It looks to me like the problem is that you are still using the base query.
You can change this by adding your variable $my_query2 in the code like this:
<?php if ($my_query2->have_posts()) : ?><?php while ($my_query2->have_posts()) : $my_query2->the_post(); ?>
This will make all the functions like the_title(), the_content(), etc work as intended since they will be set to $my_query2.

Switching between posts in wordpress

I have created a sidebar.php-file with the code;
<section class="sidomeny"><p class="Senastenytt2"><?php get_search_form();?></p></section><!--Slut på sidomeny-->
<div id="nyhet3">
<?php
query_posts('category = all');
if (have_posts()) :
while (have_posts()) : ?>
<?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>
<?php
endwhile;
endif;
?>
</div><!--Slut på Nyhet3-->
And now I would like to add the function that if you press the sidebar news section, the "textnyhet2" section will get updated with the news you clicked on. That is how it's working now.
But the problem is that the sidebar vanished whenever you click on one of those "latest news" links. So what I need help with is to edit the sidebar.php-file so the "latest news" function with links is still there so you don't have to go back one page whenever you would like to read about another post.
Im not sure how to do this. If it's php involved or if you can do it by simple visiting the posts/pages section in wordpress.
Would be grateful if anyone could help me. If I have forgotten any necassary information please tell me and I will the post.
Thanks!
<?php
get_header();
?>
<section class="textinnehall">
<?php
if (have_posts()) :
while (have_posts()) :
the_post();
the_content();
endwhile;
endif;?>
</section>
<section class="sidomeny">
<?php
get_sidebar(); ?>
</section>
<?php
get_footer();
?>
This is my page.php file. Don't know if it will be to any help. But the sidebar is already active.
May be the sidebar is not called in your single page.
you need to have the same design in your themes single.php page(As per twenty ten theme standard).
<p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
The href <?php the_permalink() ?> takes the post to single page for full view
Just call the sidebar in your theme's single page.

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.

Categories