WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Creating dynamic menu widget for custom post types (3 posts)

  1. richiesun
    Member
    Posted 4 years ago #

    Just upgraded to 3.0. Putting together a new site and trying to factor the balance between hard coding vs. using the new Menu and Widget features. I'm using the menu feature to control my main menu and I'd like to use the widget feature also without having to hard code sidebar type stuff in there.

    Here is my issue:
    1. I have a custom post type called "Downloads".
    2. I want to use the "Custom Menu" widget and add it to the primary widget area.
    3. I can create a "Downloads" Menu inside the menu area, but I can only select single posts from the "Downloads".

    How can I get it so the menu is dynamic and will display recent downloads? I basically want to have a widget that is a "Custom Menu" attached to the "Downloads" menu that displays the most recent downloads.

  2. MichaelH
    Member
    Posted 4 years ago #

    Might not be exactly what you want but consider downloading and installing Otto's PHP Code Widget, then something like this code in one of those widgets:

    <?php
    $args=array(
      'post_type' => 'downloads',
      'post_status' => 'publish',
      'posts_per_page' => 7,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. richiesun
    Member
    Posted 4 years ago #

    Short of having this functionality built into the widgets UI, this is the next best thing. Keeps me in the UI and I have the flexibility of writing code. Thanks a bunch.

Topic Closed

This topic has been closed to new replies.

About this Topic