Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress最新帖子菜单项_Wordpress_Menu_Posts - Fatal编程技术网

Wordpress最新帖子菜单项

Wordpress最新帖子菜单项,wordpress,menu,posts,Wordpress,Menu,Posts,我想让Wordpress给我一个菜单项,让我去最新的帖子。它们出现在首页上,但一旦我离开了,我希望有一个菜单项回到那里。这看起来很明显,但几个小时后,我能做的最好的事情就是创建一个自定义菜单,其中包含指向未分类菜单的链接,作为解决方法。一定有更好的办法!这样,我得到了一个盒子,上面写着未分类类别下归档的帖子档案。不要 在模板目录中创建自定义页面http://codex.wordpress.org/PagesPage_Templates 在或处使用自定义查询检查 在管理员中创建一个页面并选择您创建

我想让Wordpress给我一个菜单项,让我去最新的帖子。它们出现在首页上,但一旦我离开了,我希望有一个菜单项回到那里。这看起来很明显,但几个小时后,我能做的最好的事情就是创建一个自定义菜单,其中包含指向未分类菜单的链接,作为解决方法。一定有更好的办法!这样,我得到了一个盒子,上面写着未分类类别下归档的帖子档案。不要

在模板目录中创建自定义页面http://codex.wordpress.org/PagesPage_Templates 在或处使用自定义查询检查

在管理员中创建一个页面并选择您创建的模板

在菜单中添加指向此页面的链接,您就完成了。

也许这会有帮助:

它是一个过滤器,将“搜索并替换”占位符锚,例如“latestpost1”,并使用最新帖子的实际url,从而在呈现菜单之前动态修改菜单


我不确定这对SEO有什么影响,但这是一个聪明的解决方案。

给你所有的帖子起一个分类名称。使用一些通用的东西,比如新闻、文章或博客。然后,使用从“类别”下的菜单页中选择的名称选择类别。将此类别链接添加到菜单中。可以随意重命名链接,例如Blog。而且,viola-当人们点击该链接时,你的所有帖子都会出现。

试试这个插件:效果非常好,代码在这里是开源的:

简单解决方案:

我拿走了这家伙的密码:

基本上,他写的是为了让菜单项链接到最新的帖子,而不是帖子的复数形式,所以我只是修改了它,它开始工作了:

<?php
if ( ! is_admin() ) {
    // Hook in early to modify the menu
    // This is before the CSS "selected" classes are calculated
    add_filter( 'wp_get_nav_menu_items', 'replace_placeholder_nav_menu_item_with_latest_post', 10, 3 );
}

// Replaces a custom URL placeholder with the URL to the latest post
function replace_placeholder_nav_menu_item_with_latest_post( $items, $menu, $args ) {

    // Loop through the menu items looking for placeholder(s)
    foreach ( $items as $item ) {

     // Is this the placeholder we're looking for?
        if (!strpos(($item->url), 'latestpost'))
            continue;
      //  if ( 'latestpost' != $item->url )
        //    continue;

        // Get the latest post
        $latestpost = get_posts( array(
            'numberposts' => 1,
        ) );

        if ( empty( $latestpost ) )
            continue;

        // Replace the placeholder with the real URL
        $new_link = $item->url;
        $new_link = substr($new_link, 0, strlen($new_link) - 12);
        $item->url = $new_link;
    }

    // Return the modified (or maybe unmodified) menu items array
    return $items;
}

谢谢,但这听起来有点吓人,超出了我的能力。我敢肯定,我看到的大多数博客都会自动这样做——点击主页,你就会回到主页,上面有最新的帖子。我错过了什么?由于某些原因,我无法在“设置”>“阅读”中将frontpage和posts页面设置为相同。我想放弃。这么简单的事情,浪费了一整天!以上的解决方案是唯一的吗?我不确定我能不能绕过它!您还可以编辑archive.php页面模板,并在此处更改h1标记内的内容。你的分类页面将有一个不同的标题,并且找不到在未分类分类下归档的文章档案。这样就可以了。当您单击菜单屏幕侧面的“页面”框中的“查看全部”时,是否有“主页:主页”选项?如果没有,您是否尝试过创建指向首页URL的自定义链接?