【问题标题】:Wordpress single page theme - how to get the ids of the pages from the menuWordpress 单页主题 - 如何从菜单中获取页面的 id
【发布时间】:2012-08-24 10:15:03
【问题描述】:

我有一个问题,我有一个单页 wordpress 主题,我想在其中实现 WP 菜单。我创建了一个自定义walker,这样我就可以创建#post-slug 或#page-slug 之类的链接,而不是将用户重定向到另一个页面,但是当我需要从主页上的菜单中显示帖子时就会出现问题。

显然,我无法在一个查询中同时显示页面和帖子,因此唯一的解决方案是创建两个查询,但是,如何获取在外观 > 菜单中添加的帖子或页面的 ID?我只需要页面或帖子,而不需要自定义链接或类别/等。

非常感谢任何帮助。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    试试这个

    <?php the_ID();
    

    参考:http://codex.wordpress.org/Template_Tags/the_ID

    这个函数显示帖子的ID,返回ID使用get_the_ID()

    编辑 我很确定你需要wp_get_nav_menu_items( $menu, $args ); 函数。

    参考:http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items

    【讨论】:

    • 恐怕这不是我需要的,我需要一个函数来返回我在外观 > 菜单中的自定义菜单中添加的页面/帖子的 ID,正如我在最初的帖子中所说的那样
    • 如果你需要所有页面的所有id,试试get_pages( $args );codex.wordpress.org/Function_Reference/get_pages
    • 我需要获取我在 Appearance -> Menus 中设置的特定菜单的页面 ID,而不是数据库中的所有页面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    相关资源
    最近更新 更多