将一些HTML代码添加为帖子不起作用,但如果直接添加到文件中就行了吗?

时间:2011-03-18 作者:janoChen

我在模板文件中有一些代码。当我从后端的post面板(HTML选项卡)将其粘贴为post,并将其作为自定义循环检索时,代码输出不好。

有什么建议吗?

将其添加为帖子:

<?php
/**
 * Template Name: Lyrics Page
 * @package WordPress
 * @subpackage Prominent
 * @since Prominent 1.0
 */
get_header(); ?>
<div id="tagline">
    <div class="container">
        <?php // Run main loop (The Loop). ?>
        <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
        <div class="content0">
        </div>
        <?php endwhile; ?>
    </div><!-- .container -->
</div><!-- #content-bottom -->
<div id="content">
    <div class="container">
        <div id="mainbar">
            <div id="accordions-top">
            <?php $custom_posts = new WP_Query(); ?>
            <?php $custom_posts->query(\'category_name=Lyrics\'); ?>
            <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?>
                <?php the_content(); ?>
            <?php endwhile; ?>
            </div>
        </div><!-- #mainbar -->
        <?php get_sidebar(); ?>
    </div><!-- .container -->
</div><!-- #content-bottom -->
<?php get_footer(); ?>
直接在文件上:

<?php
/**
 * Template Name: Lyrics Page
 * @package WordPress
 * @subpackage Prominent
 * @since Prominent 1.0
 */
get_header(); ?>
<div id="tagline">
    <div class="container">
        <?php // Run main loop (The Loop). ?>
        <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
        <div class="content0">
            <?php the_content(); ?>
        </div>
        <?php endwhile; ?>
    </div><!-- .container -->
</div><!-- #content-bottom -->
<div id="content">
    <div class="container">
        <div id="mainbar">
            <div id="accordions-top">
                            <div class="basic" style="float:left; margin-left: 2em;" id="list1e">
                        <a>There is one obvious advantage:</a>
                        <div>
                            <p>
                                You\'ve seen it coming!<br/>
                                Buy now and get nothing for free!<br/>

                                Well, at least no free beer. Perhaps a bear,<br/>
                                if you can afford it.
                            </p>
                        </div>
                        <a>Now that you\'ve got...</a>
                        <div>
                            <p>
                                your bear, you have to admit it!<br/>

                                No, we aren\'t selling bears.
                            </p>
                        </div>
                        <a>Rent one bear, ...</a>
                        <div>
                            <p>
                                get two for three beer.
                            </p>
                            <p>

                                And now, for something completely different.<br/>
                                And now, for something completely different.<br/>
                                And now, for something completely different.<br/>
                                And now, for something completely different.<br/>
                                And now, for something completely different.<br/>
                                And now, for something completely different.<br/>

                                And now, for something completely different.<br/>
                                And now, for something completely different.<br/>
                                Period.
                            </p>
                        </div>
                </div>
            </div>
        </div><!-- #mainbar -->
        <?php get_sidebar(); ?>
    </div><!-- .container -->
</div><!-- #content-bottom -->
<?php get_footer(); ?>
通过管理面板添加帖子时的输出:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />

  <title></title>
</head>

<body>
  <div id="content">
    <div class="container">
      <div id="mainbar">
        <div id="accordions-top">
          <div class="basic" style="float:left; margin-left: 2em;" id="list1e">
            <a>There is one obvious advantage:</a>

            <div>
              <p>You&rsquo;ve seen it coming!<br />
              <br />
              Buy now and get nothing for free!<br /></p>

              <p>Well, at least no free beer. Perhaps a bear,<br />
              <br />
              if you can afford it.</p>
            </div>

            <p><a>Now that you&rsquo;ve got&hellip;</a></p>

            <div>
              <p>your bear, you have to admit it!<br /></p>

              <p>No, we aren&rsquo;t selling bears.</p>
            </div>

            <p><a>Rent one bear, &hellip;</a></p>

            <div>
              <p>get two for three beer.</p>

              <p>And now, for something completely different.<br />
              <br />
              And now, for something completely different.<br />
              <br />
              And now, for something completely different.<br />
              <br />
              And now, for something completely different.<br />
              <br />
              And now, for something completely different.<br />
              <br />
              And now, for something completely different.<br /></p>

              <p>And now, for something completely different.<br />
              <br />
              And now, for something completely different.<br />
              <br />
              Period.</p>
            </div>
          </div>
        </div>
      </div><!-- #mainbar ==ý-->
    </div>
  </div>
</body>
</html>

1 个回复
最合适的回答,由SO网友:janoChen 整理而成

最后,我发现我需要这个:

remove_filter(\'the_content\', \'wpautop\');

结束

相关推荐

是否可以读取帖子的ID,然后将其插入帖子的html中?

如果可能的话,我想在将帖子加载到视口中时,将帖子的ID(来自自定义帖子类型)插入到帖子本身的html中。场景是,自定义帖子类型的内容由<div>. 我想在<div> 这包括帖子的ID。例如,如果自定义帖子类型为glossary,帖子ID为351,则生成的html为:<div id=\"glossary351\"> Post content </div>我查看了条件语句并在google上搜索了该主题,但发现许多查找帖子ID的应用程序都是在页面上