【问题标题】:Wordpress menu not showing on home pageWordpress 菜单未显示在主页上
【发布时间】:2012-09-06 19:34:17
【问题描述】:

有以下问题。在稍微定制的 211 版本中,我无法在主页上显示菜单。
主页显示最新帖子。菜单在所有页面(帖子、页面、自定义页面)中都可以正常工作,但在主页上却不行。但在主页上,它显示了指向我拥有的页面的链接。 所有页面的头文件都相同,包含:

<?php wp_nav_menu(); ?>

$args 添加到"menu_id"=&gt;10 /* menu id here */ 和/或"menu"=&gt;"mymenu"
将主页类型更改为某个页面可以使菜单工作,而对index.php 使用一些不同的文件(如单个文件或页面)则不会。可能原因在某个地方。仔细研究过 wp-admin 并用谷歌搜索。
请帮帮我。

<?php
/**
 * The Header for our theme.
 *
 * Displays all of the <head> section and everything up till <div id="main">
 *
 * @package WordPress
 * @subpackage iwtech
 * @since iwtech.ru theme 1.0
 */
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title><?php
    global $page, $paged;
    wp_title( '|', true, 'right' );
    bloginfo( 'name' );
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) )
        echo " | $site_description";
// Add a page number if necessary:
    if ( $paged >= 2 || $page >= 2 )
        echo ' | ' . sprintf( __( 'Page %s', 'iwtech' ), max( $paged, $page ) );
    ?>
</title>
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'template_directory' ); ?>/styles.css">
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'template_directory' ); ?>/n-corr.css">
<script type="text/JavaScript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" >
<?php
if ( is_singular() && get_option( 'thread_comments' ) )
    wp_enqueue_script( 'comment-reply' );
?>
<?php if (isset($_POST['s2_admin'])): ?>
    <script type="text/javascript">
    document.location.reload(true)
    </script>
<?php endif; ?>
<?php 
wp_head();
?>
</head>
<body <?php body_class(); ?>>
    <div id="header">
        <?php 
        wp_nav_menu(); ?>
    </div>
</div>
<div id="wrapper">

搞定!​​

    function my_get_posts( $query ) {
    if ( is_home() )
        $query->set( 'post_type', array( 'post',  'albums', 'artists', 'clips', 'events' ) );

    return $query;
}
add_filter( 'pre_get_posts', 'my_get_posts' );

functions.php 中的这个函数破坏了navmenu

但我需要这样的东西才能在主页上自定义帖子类型,而不仅仅是帖子。 我该怎么办?

【问题讨论】:

  • 已将代码添加到我的问题中

标签: wordpress themes


【解决方案1】:

所以,最后我发现这应该是代码:

function my_get_posts( $query ) {
    if ( $query->is_main_query() and is_home() ) {
        $query->set( 'post_type', array( 'post',  'albums', 'artists', 'clips', 'events', 'quote', 'attachment' ) );
    }
    return $query;
}
add_filter( 'pre_get_posts', 'my_get_posts' );

希望它对其他人有用:-)

【讨论】:

    【解决方案2】:

    试试这个代码..希望能有所帮助

    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts( $query ) {
    
     if ( ( is_home() && false == $query->query_vars['suppress_filters'] )  ) {
        $query->set( 'post',  'albums', 'artists', 'clips', 'events', 'quote', 'attachment' ) );
    
    return $query;
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多