Link a page to a sidebar widget
-
I’m questioning myself if it’s really this difficult, or that it just sound like it is 😉
Summed up: I want a list of posts on a page, connected to a different date then the post date. That different date should be used to show the link in a widget on the correct date.
Well, in theory, I think you would need to first create a new field for each post so that the “day of release” could be retained. Then, you would need to create a function in a php widget which would only display posts where your custom field matched the current date.
Just don’t ask me the correct syntax to use 😉
Admin
You can use the custom fields in the post to give them the release date. Then you can create a custom query in the sidebar using PHP Widget to only show posts whose release date matches the current date.
And I just realised that is sort of what Josh was saying.
You can manually edit the “publish date” of a post.
So, why not write special whort “Released today” notes and put them in a special category, and edit their date to be the release date?
Then your coding for the widget would be simpler: loop through all posts in the relevant category, and show the post if current time – publishing time is less than 24 hours…
This is really hard to accomplish guys! I think Syahir’s method sounds best because I don’t want to change my publish dates.
How do you make a custom query that searches the custom fields for the dates that match the current date? sorry I’m asking this much, but I would really like this to work (I’ve been Googling all weekend on this one)
Admin
You’ll need to use the WP_Query() class for the custom query. http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
Something like this will probably work:
$args = array(
'meta_key' => 'release-date',
'meta_value' => date( 'j F Y' ), // Modify parameter to match your date format
);
$posts = new WP_Query( $args );Then make sure you run the loop to loop through the posts found (if any).
I know it’s been a while since I replied on this one, but still working on it. This is what I’ve done:
I gave a post a custom field called: ‘Release date’ and gave it this value: ’05-12-2011′.
I added a PHP cod widget with this code:
<?php
$args = array(
'meta_key' => 'release-date',
'meta_value' => date( 'D M Y' ),
);
$posts = new WP_Query( $args );
?>The box is still not showing anything now, what am I missing? 🙂
Make sure the date format you are using as the value matches the date format in Syahir’s code.
So, using your date format of
05-12-2011, the code should be this:<?php
$args = array(
'meta_key' => 'release-date',
'meta_value' => date( 'd-m-Y' ),
);
$posts = new WP_Query( $args );
?>See this for reference, http://php.net/manual/en/function.date.php
Notice the lower case
dandm, and the hyphens. Not sure if that’s the problem, though…Maybe name your custom field
release-dateinstead ofRelease date??
- You must be logged in to reply to this topic.
