Forums

[resolved] Using page featured image as wp_list_pages link background (3 posts)

  1. shakingpaper
    Member
    Posted 1 year ago #

    Updating a friends site so they can have more control over managing it. Previously, they would supply me with an image of the text and I would create a simple rollover (using css background-position technique).

    My idea was for my friend to upload the on/off state image (using the same dimensions each time) as the page featured image. I would then add the: <?php the_post_thumbnail(''); ?> snippet into the

  2. and apply the CSS.

    I found a function hack (This one) that would allow me to edit the output of the li as regular wp_list_pages doesn't, however that is about the extent of my PHP abilities. Below is what I have but it's as far as I have been able to work out.

    <?php echo wp_list_pages_custom('sort_column=menu_order&echo=0&title_li=', 'tag_open=<p style="background: url(<?php the_post_thumbnail(); ?>">&tag_close=</p>&use_link=1&use_class=1'); ?>

    Any advice would be greatly appreciated.

  • alchymyth
    The Sweeper
    Posted 1 year ago #

    have you checked your code with a fixed image url yet?
    does that work?

    unfortunately for your code, the_post_thumbnail() will output the whole html img tag;

    check this to get just the featured image url:
    http://www.leewillis.co.uk/getting-url-post-thumbnails-wordpress/

  • shakingpaper
    Member
    Posted 1 year ago #

    Thanks for the tip. Eventually just went with text based links to save on the headaches.

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags