• Resolved markellison

    (@markellison)


    My work-in-progress site: https://bit.ly/al4Jg3

    This site is for literary magazine. Each physical issue is presented on the website as a WP post, with one post per issue.

    The current issue is promoted on the righthand sidebar with its title and featured image. This is achieved by assigning to each issue post the category of “issues” and using the plugin Category Thumbnail List (a sidebar widget) to display this category’s most recently published post. Hooray!

    My problem: I’d like the navigation menu link “Current Issue” to point to the exact same thing as the sidebar widget, eg. to the most recently published post under the category “issues”. I’d like this to update automatically, just like the sidebar widget does.

    Can someone please help? Is there a code snippet that would do the trick?

    Many thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Something like:

    <?php
    global $post;
    $myposts = get_posts('numberposts=1&category_name=Issues');
    foreach($myposts as $post) :
        setup_postdata($post);
        $issue_link = '<a href="' . get_permalink() . '">Current Issue</a>';
    endforeach; ?>

    should provide you with the current issues link in a variable called $issue_link that you may then be able to add to your menu.

    Thread Starter markellison

    (@markellison)

    Thanks esmi, I tried that and although it didn’t really work, it pointed me in the right direction and I ended up doing this:

    <?php query_posts('category_name=issues&showposts=1'); ?>
    	<?php while (have_posts()) : the_post(); ?>
            	<li id="current"><a href="<?php the_permalink(); ?>"></a></li>
            <?php endwhile; ?>

    Works great!

    Thread Starter markellison

    (@markellison)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Make a link point to the most recently published post of a certain category’ is closed to new replies.