Forums

sliding door with post thumbnail (5 posts)

  1. bhenselmann
    Member
    Posted 1 year ago #

    Hi Wayne,

    I found your sliding door theme interesting, but wondering, why not using post thumbnails as sliding images, which could be uploaded and edited simply in the WP-mediathek.
    There has to be made only some small changes in the function.php and the header.php.

    In header.php change
    <?php slider_menuparse(wp_list_pages('sort_column=ID&depth=1&number=7&title_li=&echo=0')); ?>
    to
    <?php slider_menuparse(get_pages('sort_column=menu_order&child_of=0&parent=0&hierarchical=0&number=7')); ?>
    (btw: For me it was better to sort the pages acc. to the menu_order)

    In function.php add at the beginning
    <?php if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails' );
    }
    ?>
    to initialise post thumbs in the theme.

    In function.php change the function slider_menuparse() to

    function slider_menuparse($pages){
    $output = "";
    foreach ($pages as $page){
    $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id($page->ID), 'full');
    $output .= '<li class="page-item page-item-' . $page->ID .'">ID) . '" title="' . $page->post_title . '" style="background: url(' . $thumbnail_url[0] . ') no-repeat;">' . $page->post_title . '';
    }
    echo $output;
    }

    Greetings
    Bernhard

  2. wayneconnor
    Member
    Posted 1 year ago #

    Yep thanks,
    I've upgraded it to use featured image. It was not as simple as you suggested, lots of custom code needed, that's why it's taken a while.
    Wayne

  3. bhenselmann
    Member
    Posted 1 year ago #

    Fine! I´ll try it out. In the meantime I made some additional changes to the code to use more or less than 7 pages in the sliding menu with calculating the width of the sliders. And I´m thinking on including a custom field to tell the theme which page has to be used in the sliding menu and which not.
    If you´re interested I´ll send the code.
    Greetings
    Bernhard

  4. wayneconnor
    Member
    Posted 1 year ago #

    Sound great Bernhard - I'd love to see the adjustable width code and might incorporate it in.

    Wayne

  5. bhenselmann
    Member
    Posted 1 year ago #

    OK - this is the modified code I´m using for the adjustable width (but not with the mentioned costum field, which is not ready yet) :

    [please use the 'code' button to mark the code; also, in future, please use the pastebin when posting code longer than 10 lines.]

    function slider_menuparse($pages, $postID){
    $output = "";
    $count = count($pages);
    $menuwidth = 133*7; /* the imageMenu-width in px */
    if (get_post_type( $postID ) == 'post') $postID=get_option('page_for_posts'); /* this is to include the css-class current_page_item when a page for posts is defined in WP options */
    foreach ($pages as $page){
    $cp = ""; /* for css-class of current_page_item */
    $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id($page->ID), 'full');
    if ($page->ID == $postID) $cp= " current_page_item ";
    $output .= '<li class="page-item page-item-' . $page->ID . $cp . '">ID) . '" title="' . htmlentities($page->post_title) . '" style="background: url(' . $thumbnail_url[0] . ') no-repeat; width:' . $menuwidth/$count . 'px;">' . $page->post_title . '';
    }
    echo $output;
    }

    I used tis in the websites
    http://www.art-room9.de/
    and
    http://www.art-gegenwart.com/
    but maybe you have to adjust it?
    Greetings
    Bernhard

Topic Closed

This topic has been closed to new replies.

About this Topic