【问题标题】:The wordpress loop doesn't return the post structurewordpress 循环不返回帖子结构
【发布时间】:2013-05-15 22:01:42
【问题描述】:

我刚刚安装了最新的 Wordpress 版本 (3.5.1),当我像往常一样添加循环时,它不会返回正常的结构。

这是我的 php:

<?php get_header(); ?>
    <?php
        $pageid = get_query_var('page_id');
        $postid = $post->ID;
    ?>

<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
  <div class="wppost" id="post-<?php the_ID(); ?>">
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><h1><?php the_title(); ?></h1></a>

      <div class="wpentry"><?php the_content(); ?></div>
      </div>
      <?php endwhile; ?>
        <div class="wpnavigation">
          <?php posts_nav_link('','F&ouml;reg&aring;ende sida','N&auml;sta sida'); ?>
        </div>
    <?php else : ?>
      <div class="wppost" id="post-<?php the_ID(); ?>">
        <h1><?php _e('Inl&auml;gget hittades inte'); ?></h1>
      </div>
  <?php endif; ?>

这通常有效。但它现在所做的只是返回 -elements 中的内容。

它不会返回 wppost、the_title、wpentry 或任何东西,除了我在帖子本身中写的内容(到目前为止只有文本)。

这是新事物还是我做错了什么?我已经这样做了几年,到目前为止它一直有效。我被难住了。

这是来自 header.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">

<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>

<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> 
<meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats please -->

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" />
<link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

<?php wp_get_archives('type=monthly&format=link'); ?>
<?php //comments_popup_script(); // off by default ?>
<?php wp_head(); ?>


</head>
<body>

    <div id="container">
        <div id="maincontainer">


            <div id="header">
                <a href="#" title="Descending Chaos"><img alt="Descending Chaos" src="<?php bloginfo('template_directory'); ?>/images/liveheader.png" /></a>
            </div>

            <div id="top">
                <div id="menu">
                    <ul>
                        <?php wp_list_pages('title_li=','sort_column=menu_order'); ?>
                    </ul>
                </div>
                <div id="social">
                    <ul>
                        <li><a href="#" title=""><img alt="Descending Chaos on Spotify" src="<?php bloginfo('template_directory'); ?>/images/spotlogo.png" /></a></li>
                        <li><a href="#" title=""><img alt="Descending Chaos on Reverbnation" src="<?php bloginfo('template_directory'); ?>/images/reverblogo.png" /></a></li>
                        <li><a href="#" title=""><img alt="Descending Chaos on Facebook" src="<?php bloginfo('template_directory'); ?>/images/facelogo.png" /></a></li>
                        <li><a href="#" title=""><img alt="Descending Chaos on YouTube" src="<?php bloginfo('template_directory'); ?>/images/youlogo.png" /></a></li>
                    </ul>
                </div>
            </div>

编辑:用更多代码更新了原始帖子。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    如果您在循环之前运行&lt;?php print_r( $post ); ?&gt;,您应该能够看到查询。如果它没有返回任何内容,则说明查询有问题。你在这里得到的代码看起来不错。

    【讨论】:

    • 它返回未格式化的内容,即本例中的文本。
    【解决方案2】:

    我将您的代码添加到了我的开发站点,它可以在那里工作,所以我认为您的代码没有问题。

    尝试将&lt;?php wp_reset_query(); ?&gt; 放在循环之前。也许$wp_queryglobal post data 在你的循环之前被修改并且需要恢复。

    【讨论】:

    • 试过了,没用。您使用的是相同的 Wordpress 版本吗?我已经使用标题中的内容更新了原始帖子。以及循环本身之前的几行代码。虽然我怀疑它们有什么不同,因为将它们注释掉也无济于事。
    • 那个循环在哪里?在哪个模板中?
    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    相关资源
    最近更新 更多