如果content为null,则不显示div

时间:2016-06-30 03:36:36

标签: php html wordpress

我有一个内容包含在由c.cpp:26: error: template parameter 'typename std::enable_if<(! std::is_fundamental::value), int>::type <anonymous>' c.cpp:36: error: redeclared here as 'typename std::enable_if<std::is_fundamental::value, int>::type <anonymous>' 生成的div中。有可能内容为null它只生成了什么,但我想隐藏包装内容的div。

我已经完成了将它放在一个循环中,一旦我声明the_content它不起作用或变量的声明正在生成它,尽管我的主要观点是将值存储到该函数。以下是我的所作所为。

$pageContent

这是什么行不通。

<div id="content" class="clearfix row">
    <div id="main" class="col col-md-12 clearfix" role="main">
        <?php if ( have_posts() ) {
            while ( have_posts() ) {
                the_post();
                the_content();
                $thispage=$post->ID;
            }
        } ?>
        <div class="page-header"><h1><?php the_title(); ?></h1></div>

    <?php $childpages = query_posts('orderby=menu_order&order=asc&post_type=page&post_parent='.$thispage);
        if($childpages){ 
                echo '<div class="page-content">';
                foreach ($childpages as $post) :
                setup_postdata($post); ?>
                <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article">
                        <h2><?php the_title(); ?></h2>
                    <div class="page-image img-responsive"><?php the_post_thumbnail(full);?></div>
                    <?php 
                        if ($pageContent->the_content != '') {
                            echo '<div class="page-content">'.$pageContent.'</div>'; }
                        }   
                    ?>
                </article>      
         <?php
              endforeach;
                echo '</div>';
         } ?>
    </div>
</div>

通常我会用这个替换代码才能工作。即使在内容的空状态下也会生成div。

<?php 
                        if ($pageContent->the_content != '') {
                            echo '<div class="page-content">'.$pageContent.'</div>'; }
                        }   
                    ?>

这也有效,我觉得应该是错的。 $ <div class="page-content"><?php the_content();?></div> 正在生成内容而不是if条件。

pageContent = the_content();

4 个答案:

答案 0 :(得分:1)

你是对的,the_content()回应内容而不是回复它。阅读WordPress manual。你会找到源代码:

function the_content( $more_link_text = null, $strip_teaser = false) {
  $content = get_the_content( $more_link_text, $strip_teaser );

  /**
   * Filter the post content.
   *
   * @since 0.71
   *
   * @param string $content Content of the current post.
   */
  $content = apply_filters( 'the_content', $content );
  $content = str_replace( ']]>', ']]&gt;', $content );
  echo $content;
}

如您所见,它会输出内容。您可以使用get_the_content()来检查是否有。然后输出您的<div>或您想要的内容,拨打the_content(),然后输出</div>。不要试图将the_content连接成一个字符串。

您可能还希望将get_the_content()存储到变量中并应用过滤器,并在if块中自行替换字符串。

答案 1 :(得分:0)

如果/** * Created by Ninan John J P on 6/30/2016. */ import java.util.Scanner; public class JavaApplication62 { public static void main(String[] args) { while (true) { Scanner in = new Scanner(System.in); System.out.println("1.Enroll Student"); System.out.println("2.Offer Course"); //String name = in.next(); Not required. This will want a text input before proceeding further. int choice = in.nextInt(); if (choice == 1) { student_class[] studentList = new student_class[500]; studentList[0] = new student_class(); while (true) { System.out.print(" Enter name of the student: "); studentList[0].setName(in.next()); System.out.println(""); System.out.print(" The student is given the unique ID = " + studentList[0].getUniqueStudentID() + " and the number of students = " + studentList[0].getNumberOfStudents()); /* System.out.print("> and the number of students : "); //studentList[0].setnumberOfStudents(in.nextInt); studentList[0].setNumberOfStudents(in.nextInt()); */ //This is not required. You have already done this in the previous print statment. System.out.println(""); System.out.print(" Enter the e-mail address of the student: "); //studentList[0].setemail(in.next); you are calling the wrong method. Also in.next should be a method. studentList[0].setEmail(in.next()); System.out.print("Enter the semester number of the student: "); // studentList[0].setsemesterNumber(in.nextInt); // same as prev error studentList[0].setSemesterNumber(in.nextInt()); System.out.print(" Add another student (Y/N): "); char add = in.next().charAt(0); if (add == 'Y' || add == 'y') { } if (add == 'N' || add == 'n') { break; } } } else if (choice == 2) { while (true) { Course[] courseOfferedList; courseOfferedList = new Course[500]; courseOfferedList[0] = new Course(); System.out.println("Enter the course code : "); //courseOfferedList[0].setCourseCode(in.next()); // next() returns a string. You need nextInt() here. courseOfferedList[0].setCourseCode(in.nextInt()); System.out.println(" Enter the course title: "); courseOfferedList[0].setCourseTitl(in.next()); System.out.println(" Enter the credit hours of the course: "); courseOfferedList[0].setCreditHours(in.nextInt()); System.out.print(" Add another course (Y/N): "); char add2 = in.next().charAt(0); // if (add2 == 'Y' || add2 == 'y') { // not needed // } if (add2 == 'N' || add2 == 'n') { break; } } } } } } 生成内容,为什么不用它来检查呢

所以而不是

the_content()

尝试以下代码

        <?php 
            if ($pageContent->the_content != '') {
                echo '<div class="page-content">'.$pageContent.'</div>'; 
            }   
        ?>

答案 2 :(得分:0)

你可以在下面添加它运行的PHP代码。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity"
    android:elevation="7dp">

    <include
        layout="@layout/app_bar_get_sensors"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
       />

</android.support.v4.widget.DrawerLayout>

答案 3 :(得分:0)

使用此代码,这将对您有用。

<?php if(the_content() ) { ?>
    <div class="page-content">
<?php the_content();?>
</div>
<?php } else{
echo "div not showing";
} ?>