Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.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
Php Wordpress帮助显示依赖于页面的帖子类别_Php_Wordpress - Fatal编程技术网

Php Wordpress帮助显示依赖于页面的帖子类别

Php Wordpress帮助显示依赖于页面的帖子类别,php,wordpress,Php,Wordpress,我想根据页面显示特定的帖子类型,例如,我有一个博客帖子类型,我想显示当用户在/blog时,我有一个链接帖子类型,并且想在用户在/link时显示这些。这是可能的吗?目前我在index.php中有这段代码 <?php get_header(); ?> <div id="content"><!-- CONTENT START --> <h2><?php echo ucwords($post->post_title);?></h2&

我想根据页面显示特定的帖子类型,例如,我有一个博客帖子类型,我想显示当用户在/blog时,我有一个链接帖子类型,并且想在用户在/link时显示这些。这是可能的吗?目前我在index.php中有这段代码

<?php get_header(); ?>
<div id="content"><!-- CONTENT START -->
<h2><?php echo ucwords($post->post_title);?></h2>    
    <div id="subNavigation"><!-- SUBNAV START -->
        <?php
            if(get_the_title($post->post_parent) == "Members Content") {
                $children .= '<li><a href="forums">Forums</a></li>';
                $children .= '<li><a href="members">Members</a></li>';
                $children .= '<li><a href="groups">Groups</a></li>';
            } else {
                $permalink = get_permalink($post->post_parent);
                $children .= '<li><a href="'.$permalink.'">'. get_the_title($post->post_parent). '</a></li>';
            }
          if($post->post_parent)
              $children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
          else
              $children .= wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
              if ($children) { ?>
                  <ul>
                      <?php echo $children; ?>
                  </ul>
              <?php } ?>        
    </div><!-- SUBNAV END -->

    <div id="contentMainInterior"><!-- CONTENT MAIN START -->
        <?php while (have_posts()) : the_post(); ?>
            <?php the_content(); ?>
        <?php endwhile; ?>                
    </div><!-- CONTENT MAIN END -->    
    <div class="clear"></div>
</div><!-- CONTENT END -->


这会让你找到正确的方向:


这会让你找到正确的方向:


如果您正在谈论自定义帖子类型,最好的方法是为每个帖子类型索引页面创建模板。例如,您有一个名为“blog”的页面,并将其指定为“blog”模板,在该模板中,您可以编辑post查询以查找
“post\u type”=>“blog\u post”
或任何您的类型

如果您正在谈论自定义帖子类型,最好的方法是为每个帖子类型索引页面创建模板。例如,您有一个名为“blog”的页面,并将其指定为“blog”模板,在该模板中,您可以编辑post查询以查找
“post\u type”=>“blog\u post”
或任何您的类型