Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.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 post_title()公告_Php_Wordpress - Fatal编程技术网

Php Wordpress post_title()公告

Php Wordpress post_title()公告,php,wordpress,Php,Wordpress,下面是我的场景:我得到了一个index.php,它可以加载我得到的每个页面。最后只有一页纸 我在网上找到了这个片段,它通过创建这个帮助了我很多 <?php $mypages = get_pages( array('child_of' => 1503, 'sort_column' => 'menu_order') ); foreach( $mypages as $page ) { $content = $pag

下面是我的场景:我得到了一个index.php,它可以加载我得到的每个页面。最后只有一页纸

我在网上找到了这个片段,它通过创建这个帮助了我很多

      <?php
        $mypages = get_pages( array('child_of' => 1503, 'sort_column' => 'menu_order') );

        foreach( $mypages as $page ) {
            $content = $page->post_content;
            if ( ! $content ) // Check for empty page
            continue;

            $content = apply_filters( 'the_content', $content );
        ?>
        <section>
            <div class="headlines info-header"><img src="<?php echo get_template_directory_uri(); ?>/assets/images/arrow.png" alt="arrow"><?php echo $page->post_title; ?></div>
            <div class="page-content"><?php echo $content; ?></div>
        </section>
        <?php
        }
      ?>

/assets/images/arrow.png“alt=”arrow“>
它似乎工作得很好。但现在是问题的一部分。我想在这一页上也显示帖子。我的尝试是创建另一页<代码>新闻并在这一页上放置一个小部件,显示最新的帖子,按类别过滤

但是现在页面标题不再显示了,我得到的只是以下内容

注意:注意:正在尝试获取中非对象的属性“POST_TITLE”

因此,我认为问题可能与小
有关,我已经尝试获取
标题,但最终得到了相同的错误

我对Wordpress有点陌生,所以我不知道如何处理这个问题。 有没有其他方法可以在my index.php上获取页面标题

最好的,
多米尼克

我设法解决了这个问题。正如@delboy1978uk告诉我的,我通过添加两行代码来检查标题是否为空

以下是最终代码:

          <?php
        $mypages = get_pages( array('child_of' => 1503, 'sort_column' => 'menu_order') );

        foreach( $mypages as $page ) {
            $content = $page->post_content;
          $title = $page->post_title;
            if ( ! $content ) // Check for empty page
          if ( ! $title) // Check for empty title < NEW!
            continue;

            $content = apply_filters( 'the_content', $content );
        ?>
        <section>
            <div class="headlines info-header"><img src="<?php echo get_template_directory_uri(); ?>/assets/images/arrow.png" alt="arrow"><?php echo $title; ?></div>
            <div class="page-content"><?php echo $content; ?></div>
        </section>
        <?php
        }
      ?>

/assets/images/arrow.png“alt=”arrow“>

可能重复的$page不是对象。检查var转储以查看您实际拥有的内容。可能是数组?可能是@MasivuyeCokile的副本,谢谢。但是这次这个方法不起作用了,因为我需要index.php上的页面标题。当我打开调试模式时,通知消失了,但我的仍不见了。