Is there a way to retrieve a post data through a menu
-
Hello everyone,
I am trying to use flexslider on my theme and I would like to use a custom menu item to reorganize the order. Is it possible to get post information by the menu ID. So far it only shows the latest post on the slide<?php // Enqueue Flexslider Files function wptuts_slider_scripts() { wp_enqueue_script( 'jquery' ); // wp_enqueue_style( 'flex-style', get_template_directory_uri() . '/inc/slider/css/flexslider.css' ); wp_enqueue_script( 'flex-script', get_template_directory_uri() . '/js/jquery.flexslider-min.js', array( 'jquery' ), false, true ); } add_action( 'wp_enqueue_scripts', 'wptuts_slider_scripts' ); // Initialize Slider ?> <?php function wptuts_slider_initialize() { ?> <script type="text/javascript" charset="utf-8"> jQuery(window).load(function() { jQuery('.flexslider').flexslider({ animation: "fade", direction: "horizontal", slideshowSpeed: 700, animationSpeed: 600 }); }); </script> <?php } add_action( 'wp_head', 'wptuts_slider_initialize' ); ?> <?php function wptuts_slider_template(){ //get all of the meta data from the list items $menu_name = 'slider'; //get all of the menus $locations = get_nav_menu_locations(); //Check to see if the menu in the location is empty if ( isset( $locations[ $menu_name ] ) ) { //get the actual menu object by the same name $menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); $menu_items = wp_get_nav_menu_items($menu); // echo var_dump($menu_items); //Start the Slider ?> <div class="flexslider"> <ul class="slides"> <?php foreach( $menu_items as $slide ){ //var_dump($slide); //echo $slide ->ID; //retrieve the id of the slider var_dump(get_post($slide ->ID)); //if the slider has a thumbnail then display it if ( has_post_thumbnail() ) ?> <li> <?php echo the_post_thumbnail() ?> </li> <?php }?> <?php }?> <?php }?>
- The topic ‘Is there a way to retrieve a post data through a menu’ is closed to new replies.