Alec Rust
Alec Rust

Reputation: 11353

Pulling Featured Images in to a WordPress Menu

I've got a simple static list marked up like this that I'd like to turn in to a WordPress Menu:

<ul>
    <li><a href="#"><img src="http://placekitten.com/200/300"></a></li>
    <li><a href="#"><img src="http://placekitten.com/200/300"></a></li>
    <li><a href="#"><img src="http://placekitten.com/200/300"></a></li>
    <li><a href="#"><img src="http://placekitten.com/200/300"></a></li>
</ul>

I'd like each list item to link to a specific post, and pull in the Featured Image rather than the title. If I setup a default WordPress Menu it would output like this:

<ul>
    <li><a href="post-1/">Blog Post 1</a></li>
    <li><a href="post-2/">Blog Post 2</a></li>
    <li><a href="post-3/">Blog Post 3</a></li>
    <li><a href="post-4/">Blog Post 4</a></li>
</ul>

How would I instead output it like this:

<ul>
    <li><a href="post-1/"><img src="post-1-featured-img.png"></a></li>
    <li><a href="post-2/"><img src="post-2-featured-img.png"></a></li>
    <li><a href="post-3/"><img src="post-3-featured-img.png"></a></li>
    <li><a href="post-4/"><img src="post-4-featured-img.png"></a></li>
</ul>

So essentially I'd just like to return the Featured Image of each post I specify in a WordPress Custom Menu rather than the post title.

Upvotes: 0

Views: 741

Answers (1)

anstrangel0ver
anstrangel0ver

Reputation: 1073

you can use to get the image but m think you cant get post feature in the menu from the default wp menu

$defaults = array(
                    'container' => '',
                    'container_class' => '',
                    'menu' => 'Main Menu',
                    'echo' => 1,
                    'items_wrap' => '<ul class="topmenu">%3$s</ul>',
                    'link_before'     => '<img src="post-1-featured-img.png"/>',
    'link_after'      => '<span class="menu_h_r"></span></a>'
                );

               wp_nav_menu($defaults);

to get the define image but m not sure you will find solution for you. try some plugins.

Upvotes: -1

Related Questions