【问题标题】:Custom post type getting wrong categories and tags自定义帖子类型获取错误的类别和标签
【发布时间】:2012-03-08 09:57:36
【问题描述】:

好的,我的博客上有一个名为视频的自定义帖子类型,我只发布视频。下面有一个镜头盖

右侧是自定义帖子类型的最新帖子,左侧是视频,视频下方是日期和时间、类别和标签。 但问题是它弄错了标签、类别和日期。 我该如何解决这个问题?

下面是那个模板页面的代码

<?php
/*
Template Name: Single Videos
*/
?>
<?php get_header() ?>

<div id="wrapper">

<div id="container">

<div id="contentfull">



    <?php the_post() ?>

        <div class="entry-wide">
            <center><h2 class="page-title2"><?php the_title() ?></h2>     </center>

            <div class="entry-videoo">
 <?php the_content() ?>



 <?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'wpbx' ) . '&after=</div>') ?>


            </div>

 <div id="videosidebar">

 <?php
 $queryObject = new WP_Query( 'post_type=videos&posts_per_page=2020&orderby=rand' );
 // The Loop!
 if ($queryObject->have_posts()) {
?>

<?php
while ($queryObject->have_posts()) {
    $queryObject->the_post();

    ?>

 <table width="100%" border="0" cellspacing="0" cellpadding="0">

 <tbody>

 <tr>

 <td valign="top" width="1%">
 <div id="videoimg"><a href="<?php the_permalink(); ?>" title="<?php printf(__( 'Read %s', 'wpbx' ), wp_specialchars(get_the_title(), 1)) ?>">
                    <?php the_post_thumbnail('video-post'); ?>
                    </a></div>
 </td>

 <td valign="top" width="90%">
   <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
 </td>

 </tr>


 </table>
 <?php
 }
 ?>
 <?php
 }
 ?>
 </div>

 <div class="entry-info">

 <div class="entry-meta-top">
                    <span class="entry-date"><font color="#e60288"><b><?php the_time(__('F jS, Y', 'kubrick')) ?></b></font></span>
                    <span class="entry-meta-sep">|</span>
                    <span class="entry-cat">Published in: <?php the_category(', '); ?> </span>


 <div id="sharing">
 <span class='st_facebook_hcount' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span><span class='st_twitter_hcount' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span><span class='st_plusone_hcount' st_title='<?php the_title(); ?>' st_url='<?php the_permalink(); ?>' displayText='share'></span></div>
            </div>

 <br>
 <?php the_tags( __( '<span class="tag-links"><strong>More On:</strong> ', 'wpbx' ), ", ", "</span>\n" ) ?>


 <div class="entry-content">
                    <?php the_excerpt(); ?>
                </div>


 </div>

 <div class="entry-commm">

 <?php comments_template(); ?></div>


        </div><!-- entry -->





</div><!-- #contentfull -->
</div><!-- #container -->
</div><!-- #wrapper -->

 <?php get_footer() ?>

【问题讨论】:

    标签: wordpress tags categories custom-post-type


    【解决方案1】:

    我认为您的问题归结于这个电话:

    $queryObject->the_post();
    

    覆盖全局$post 变量。您对(例如)the_title() 的后续调用将使用该循环中的值,而不是自定义帖子本身。尝试添加

    wp_reset_postdata()
    

    在您的 PHP 代码中 $queryObject 循环之后(即在 &lt;div class="entry-info"&gt; 之前)。

    还有一件小事——你没有关闭你的tbody标签——通过the w3c validator运行生成的HTML并纠正任何问题;它将帮助解决您将来可能遇到的任何 CSS 问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2015-10-11
      • 1970-01-01
      • 2013-05-12
      • 2023-04-04
      • 2016-08-05
      相关资源
      最近更新 更多