0

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

<?php wp_nav_menu(); ?>

添加$args"menu_id"=>10 /* menu id here *//或"menu"=>"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.

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

4

2 回答 2

0

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

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' );

希望,这对其他人有用:-)

于 2012-09-07T07:47:01.533 回答
0

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

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;
}
}
于 2013-04-30T05:10:22.617 回答