wp_get_archives, one post missing - wordpress

i'm trying to built a custom archive page.
there is a dropdownmenu for the year, whichs displays the post count (correctly). but when i pick one year, one post (the newest) is missing.
this is my dropdown
<select name="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'>
<option value=""><?php echo esc_attr( __( 'Jahr' ) ); ?></option>
<?php wp_get_archives( array( 'type' => 'yearly', 'format' => 'option', 'show_post_count' => 1 ) ); ?>
and there is my loop
<?php while(have_posts()) : the_post(); ?>
<div <?php post_class('post-programm'); ?>>
<a href="<?php the_permalink(); ?>">
<div class="entry-content">
<h3><?php the_title(); ?></h3>
</div>
</a>
</div>
<?php endwhile; ?>
i also tried a query_posts, but in this case i get all the posts, not only for one particular year.
<?php query_posts('posts_per_page=-1');
if(have_posts()) : while(have_posts()) : the_post(); ?>
thanks in advance for any help!

Is your one missing post a custom post type? wp_get_archives doesn't work with custom posts.

Related

How to get from post_class from relationship (related)

I have created two custom post types, 'offers' and 'brands'. I have made the relationship using an advanced custom fields relationship field 'related_brand'.
Each brand uses a single post and the related posts are shown on the same page, however, when using post_class on the related posts I just noticed they are displaying the brands post classes and not the related posts classes, which are different.
How can I pull in the correct post_class for the related posts bearing in mind they are two separate post types.
The following pulls in the related posts.
$offers = get_posts(array(
'post_type' => 'offers', // name of custom post type
'meta_query' => array(
array(
'key' => 'related_brand', // name of custom field
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
));
Watered down code that displays the related posts.
<?php if ($offers) : ?>
<?php foreach ($offers as $offer) : ?>
<div <?php post_class(); ?>> <!--Displaying the incorrect post classes-->
<div>
<a href="<?php the_permalink($offer->ID); ?>">
<?php echo get_the_post_thumbnail($offer->ID,); ?>
</a>
</div>
<div>
<a href="<?php the_permalink($offer->ID); ?>">
<?php echo get_the_title($offer->ID); ?>
</a>
</div>
<?php endforeach; ?>
<?php endif; ?>
In his case he is taking the post_class with the id of the current loop and not that of foreach but of the current loop of the tag.
To get it right you should use post_class with two arguments post_class ('', $ post_id); where the second is the post id. In your case the code should be + - like this:
<?php if ($offers) : ?>
<?php foreach ($offers as $offer) : ?>
<div <?php post_class('', $offer->ID ); ?>> <!--Displaying the incorrect post classes-->
<div>
<a href="<?php the_permalink($offer->ID); ?>">
<?php echo get_the_post_thumbnail($offer->ID,); ?>
</a>
</div>
<div>
<a href="<?php the_permalink($offer->ID); ?>">
<?php echo get_the_title($offer->ID); ?>
</a>
</div>
<?php endforeach; ?>
<?php endif; ?>

Wordpress List post categories that link to a page showing those posts

List post categories that link to a page showing those posts.
Hi all
I have posts with different categories.
I have a blog page that lists the posts like this.
<?php
$blog_args = array(
'post_type' => 'post',
'order_by' => 'date',
'order' => 'ASC'
);
$blog_loop = new WP_Query($blog_args);
if($blog_loop->have_posts()):
while($blog_loop->have_posts()):
$blog_loop->the_post();
?>
<div class="row">
<div class="col-sm-3 img-responsive">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('post-thumbnail', array( 'class' => "img-responsive"));
}
?>
</div>
<div class="col-sm-9">
<h3><?php echo the_title(); ?></h3>
<p><?php echo the_content(); ?></p>
</div>
</div>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>
I would like to have a list of the different categories on the blog page. If I click the category I would like to show the post with that catogory.
I can list the categories like so.
<ul>
<?php
wp_list_categories('title_li=>');
?>
</ul>
If I click the link it takes me to an empty page with the name of the category in the URL.
How can I list the categories and link to show the post with that category.
add a file in your theme called category.php then add the loop code into it.
<?php get_header(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title();?>
<?php the_content();?>
<?php endwhile; wp_reset_postdata(); endif; ?>
<?php get_footer(); ?>

Strage Problem in Wordpress Custom Post Type?

I have a blog, and I have added one custom post type 'Movies'. and I have link it to my single-movies.php. and added this code:
<div id="container">
<?php
$args = array( 'post_type' => 'movies', 'posts_per_page' => 1, 'name' => $_GET['movie'] );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1>
<a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<?php include(TEMPLATEPATH . '/sidebar_single.php'); ?>
<?php get_footer(); ?>
But Problem is, I'm clicking on any movie, its showing me only same movie, which i have added last on custom field Movies (i.e Avatar Movie, if I click on stargate movie, Its showing me 'Avatar' Movie link. and same others)
Please help me and change this code, if I did anything wrong here.
when you are in single-movies.php
it means you are already on the right path like /movies/avatar
so doing a simple loop
<?php while (have_posts()) : the_post(); ?>
<?php the_title(); //.... ?>
<?php endwhile; ?>
gives you all details of the avatar movie, you don't need to query, because the query is already made by the time you arrive to a SINGLE Movie page!
/movies/avatar means:
post type = movies
post name = avatar
also if you have pretty links, $_GET['movie'] it normally contains nothing.
it is prefered to use the $wp->query_vars['post_name'] to get the movie name
try just putting the loop and see what you get, if not dump the $_GET and $wp to see where you have the movie name.
you have a problem with the loop.
I would say to use a foreach...look at this example, maybe it will help you. it is exactly the same as you want to achieve.
<?php
$cat_id = $category->cat_ID; // YOU CAN CHANGE THIS OR REMOVE
global $post;
$args = array( 'category' => $cat_id, 'numberposts' => -1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : start_wp();
?>
<li class="subcat-post-title">
<span class="trigger">
<a class="ficha" href="<?php the_permalink() ?>">
<?php echo the_title(); ?>
</a>
<?php endforeach; ?>

How to group posts according to tag (WordPress)

I would like to list all post on one page, but I would like the posts to be grouped by tags. Is this possible in Wordpress?
Basically this way:
Bikes:
Posted 2/8/2011
Some post title 1
Tag bikes
Posted 1/8/2011
Some post title 2
Tag bikes
Cars:
Posted 5/8/2011
Some post title 5
Tag cars
Posted 29/7/2011
Some post title 6
Tag cars
Boats:
Posted 30/7/2011
Some post title 4
Tag boats
Is this possible to do? It should dynamic so that I can create new tags from WP admin and they would show up automatically.
Loop though the tags using get_tags() and use get_posts with the 'tag_in' argument.
ie.
<?php foreach(get_tags() as $term){ ?>
<?php $posts = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'project', 'tag__in' => $term->term_id ) ); ?>
<?php if($posts) : ?>
<h3><?php echo $term->name; ?></h3>
<?php foreach($posts as $post) : ?>
<?php setup_postdata($post); ?>
<div class="item col-sm-12">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?> <br/>
</a>
<a class="button" href="<?php the_permalink() ?>">Read More</a>
</div>
<?php endforeach ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php } ?>
It depends. Are you trying to show posts for all tags, or just listing all posts by specific tags you've already decided on?
If you know the tags you want to display, here is how you would list posts by tag.
<?php $bikePosts = new WP_Query('tag=bikes');
while ($bikePosts->have_posts()) : $bikePosts->the_post(); ?>
<h2>Bikes:</h2>
<p>Posted <?php the_time('j/m/Y'); ?> <?php the_title(); ?>
<?php endwhile;
//reset post data for next tag
wp_reset_postdata();
?>
More info: http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters

WordPress: Using custom field to define posts to display in loop

I'm trying to use a custom field in which I input the post ID numbers of the posts I want to show, seperated by commas. For some reason though, only the first post of the series of the post IDs are displaying. Can someone help? The value of $nlPostIds is (minus the quotes): "1542,1534,1546". Here's the code... the most important part is the 4th line 'post__in' => array($nlPostIds)
<?php
$nlPostIds = get_post_meta($post->ID, 'nlPostIds', true);
$args=array(
'post__in' => array($nlPostIds)
);
query_posts($args);
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div class="entry">
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="allinfos"><span class="date"><?php the_time('F jS, Y') ?></span> | <span class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> </span> | <span class="category">Posted in <?php the_category(', ') ?></span> <!-- by <?php the_author() ?> --></div>
<?php the_content('More ยป'); ?>
<?php the_tags('Tags: ', ', ', ' '); ?> <?php edit_post_link('Edit', '[ ', ' ]'); ?>
<div class="clear"></div>
</div></div>
<?php endwhile; endif; ?>
Thanks!
I think you need to also pass the argument 'posts_per_page' as -1 in your $args array (see the Codex on query_posts()).
UPDATE:
Apologies, I've just re-read your question and I think I know the problem. Pass $nlPostIds as the direct argument, without placing it an array. You only pass an array when each element is an ID. In this care you're just passing a comma-separated string.
UPDATE:
Use;
$args = array('post__in' => #explode(',', $nlPostIds), 'posts_per_page' => -1);

Resources