如果希望将其用作循环类型结构,可以尝试以下操作:
<?php
if ( is_user_logged_in() ) {
//Only displays if the user is logged in.
query_posts(\'cat=1\'); // Replace the category number with the correct category number you want to display
while (have_posts()) : the_post();
the_content();
endwhile;
} else {
// Everyone else that is not logged in
query_posts(\'cat=2\'); // Replace the category number with the correct category number you want to display
while (have_posts()) : the_post();
the_content();
endwhile;
}
?>
If 您希望只显示指向类别页面的链接,就像显示菜单一样。您可以执行以下操作:
使用WP nav菜单功能。在中注册菜单functions.php在主题文件夹中。您可以通过将以下内容添加到文件中来完成此操作:
<?php
register_nav_menus( array(
\'primary\' => __( \'Primary Navigation\', \'your_theme_name\' ), // Your main navigation. Replace "your_theme_name" with the theme you are using.
\'logged_in_user\' => __( \'Logged In User\', \'your_theme_name\' ), // Remember replace "your_theme_name" with the theme you are using.
) );
?>
通过管理将类别添加到菜单中。
在你的主题中调用它。这与我们上面所做的类似,但只是将其作为菜单列出,而不是发布列表。
<?php
if ( is_user_logged_in() ) {
//Only displays if the user is logged in.
wp_nav_menu( array( \'container\' => false, \'menu_id\' => \'nav\', \'theme_location\' => \'logged_in_user\' ) );
} else {
// Everyone else that is not logged in
// You can display anything you want to none logged in users or just leave it blank to display nothing.
}
?>