Link a page to a sidebar widget

  • Ricardo

    #18916

    Also really logical! I didn’t help though.

    Anonymous

    #18917

    Okay, we are going to have to run a loop checking any posts with the criteria you specified. Looking into it now…

    Ricardo

    #18918

    Thanks! I have spent so much time on this one, but I just can’t get it to work.

    Anonymous

    #18919

    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;
    }

    Ricardo

    #18922

    Unfortunately nothing happened. (I changed the date to ’06-12-2011′)

    Anonymous

    #18923

    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?

    Ricardo

    #18924

    Yes! 🙂

    Anonymous

    #18925

    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.

    Ricardo

    #18926

    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?

    Anonymous

    #18927

    🙂 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; ?>

Viewing 10 posts - 21 through 30 (of 43 total)

  • You must be logged in to reply to this topic.
Do NOT follow this link or you will be banned from the site!