Link a page to a sidebar widget
-
Okay, we are going to have to run a loop checking any posts with the criteria you specified. Looking into it now…
Okay… let’s try this… (fingers crossed)…
function ricardo-custom-posts(){
$args = array(
'meta_key' => 'release-date',
'meta_value' => date( 'd-m-Y' ),
);
$the_query = new WP_Query( $args );
//Show posts
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) : $the_query->the_post();
$myPosts .= get_post_meta($post->ID, 'mycustomfieldname', true);
endwhile;
}
return $myPosts;
}I haven’t forgotten about this. I finally got my php widget set up today. I will work on the code now.
So, just to be clear, you enter a custom field with release-date as the key, and the date as the value. Then, you want the php widget to show the posts on the current day which is assigned in the custom field? So the widget will change each day in regards to displaying the posts with the custom field of that day?
Do I understand correctly?
Here you go, my friend. Sorry this took me so long. Just paste this into your PHP widget.
Feliz Navidad 🙂
<ul>
<?php
$args = array(
'meta_key' => 'release-date',
'meta_value' => date( 'd-m-Y' ),
);
$the_query = new WP_Query( $args );
?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>All I included here was the title and the permalink (so it links to the appropriate post). You can adjust the code to display a photo, text excerpt, etc.
Amazing, after months of trying this actually works! Thank you so much! I added you to my ‘Friends’ page 😉 http://fastforwardandrewind.com/friends/
Is it also possible to make the link open in a new window?
🙂 I’ve been waiting for your response all night. I knew you’d like that one.
Remember too, the styling possibilities are limitless. You can add photos, excerpts, anything you want really.
For a new window, just change this:
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>To this:
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<li><a target="_blank" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>
- You must be logged in to reply to this topic.
