【问题标题】:wordpress custom menu with page thumbnail带有页面缩略图的wordpress自定义菜单
【发布时间】:2016-12-24 07:18:59
【问题描述】:

我正在尝试获取一个包含少量链接的菜单,并显示他们的/链接/页面特色图片。以下是我的functions.php代码。

function register_my_menus() {
  register_nav_menus(
    array(
      'main-menu' => __( 'Main Menu' ),
      'useful-links' => __( 'Userful Links' )
    )
  );
}
add_action( 'init', 'register_my_menus' );

这就是我在页面中调用它的地方。

<?php wp_nav_menu( array( 'theme_location' => 'useful-links', 'sort_column' => 'menu_order', 'container_class' => 'useful-links', 'menu'=>'Posts Menu' ) ); ?>

我知道缺少某些东西,但请提供建议。我的页面外观允许 6 个链接及其图片。

谢谢

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    这应该在您的 functions.php 中以在 WordPress 中注册菜单。

    if (!function_exists('wp_basicTemplateSetup')) {
        function wp_basicTemplateSetup() {
            // Register the Main Menus into WordPress
            register_nav_menus(array(
                'primary' => __('Main Menu', 'theme-name'),
            ));
        }
    }
    add_action('after_setup_theme', 'wp_basicTemplateSetup');
    

    在您的主题中,菜单位于何处,您需要告诉菜单功能,要查找哪个菜单。所以..:

    // Variable that tells WordPress which menu to use, look at "Theme Location"
    // Put this variable either at the top of your theme, of right *before* the  function wp_nav_menu
    
    $mainmenu = array(
        'theme_location' => 'primary',
        'container' => false,
        'menu_class' => 'some-menu-css-class',
        'depth' => 2
    );
    
    // The WordPress menu function
    <?php wp_nav_menu($mainmenu); ?>
    

    这 3 个组件是使您的 WordPress 菜单正常工作所必需的。

    【讨论】:

    • 有用的链接正在执行第一个组件。我可以在主题的特定位置调用我的菜单。只想调用锚的图像,即帖子的图像。希望你能理解。
    • 啊,不——抱歉——如果你想获得一篇文章的图片(它可能是你的第一个链接或其他什么......那么你需要查询 WordPress 的文章,而不是菜单。跨度>
    • 链接上方的任何想法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 2016-09-25
    • 2013-07-23
    相关资源
    最近更新 更多