首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >the_permalink();不工作

the_permalink();不工作
EN

Stack Overflow用户
提问于 2012-01-06 23:20:41
回答 2查看 5.8K关注 0票数 0

好吧,我对the_permalink()函数着迷了。这并不容易解释这个问题,但我会尝试。当我在我的网站(index.php)的首页上,当我点击页脚部分的链接时,它会把我带到最近的帖子(single.php),这很好。但是,当我从索引页面( index.php)开始,当我使用导航栏导航到某个页面(page.php)(它与index.php具有相同的布局),然后,当我单击页脚部分中的相同链接时,它应该将我带到最近的帖子(single.php),但它不是。它把我带到当前页面(page.php)而不是single.php。下面是我的代码片段:

页脚:

代码语言:javascript
复制
   <div id="clear"></div>

        <div id="video">
            <!--<a href="http://www.youtube.com/watch?v=WYc4ZOxRX-4" target="_blank"><img src="<?php bloginfo('template_url'); ?>/images/video_03.png" alt="Video" border="0" width="263" height="193" title="Video" /></a>-->
            <iframe width="263" height="208" src="http://www.youtube.com/embed/WYc4ZOxRX-4?rel=0" frameborder="0" allowfullscreen></iframe>
        </div><!-- end of video -->

        <div id="weeklyadbox">
            <p id="content"><a href="<?php the_permalink(); ?>"><img src="<?php bloginfo('template_url'); ?>/images/weeklyad.jpg" height="147" width="178" alt="Weekly Specials" border="0" title="Click to See Our Weekly Specials" /></a></p>
        </div><!-- end of weeklyadbox -->


        <div id="weathericon">
            <a href="<?php bloginfo("url"); ?>"><img src="<?php bloginfo('template_url'); ?>/images/icons_03.png" border="0" alt="Weather Icon" title="See Weather" height="96" width="83" /></a>
        </div>

        <div id="directionsicon">
            <a href="<?php bloginfo("url"); ?>"><img src="<?php bloginfo('template_url'); ?>/images/icons_04.png" border="0" alt="Directions Icon" title="Get Directions" height="94" width="96" /></a>
        </div>

        <div id="webcamicon">
            <a href="<?php bloginfo("url"); ?>"><img src="<?php bloginfo('template_url'); ?>/images/icons_05.png" border="0" alt="Web Cam Icon" title="Web Cam" height="96" width="84" /></a>
        </div>

        </div><!-- end of container --> 

        <div id="footer">
        &copy;<?php echo date("Y"); echo " "; bloginfo('name'); ?>
         </div>

</div>

<?php wp_footer(); ?>

当我在索引部分时,The_permalink()很好,但当我在不同的页面时就不行了。我尝试使用echo get_permalink(53),它起作用了,但是当客户端进入仪表板并创建新帖子时会发生什么呢?新帖子将有一个不同的帖子ID,该链接不会指向新帖子,但会指向ID等于53的旧帖子。

如果你需要看其他代码,请让我知道!

有什么建议吗?谢谢你的帮助!

EN

Stack Overflow用户

回答已采纳

发布于 2012-01-06 23:51:40

看起来您在WP循环之外使用了the_permalink()。get_permalink()在“循环”之外工作,因为您显式地将"Post ID“传递给函数。

请阅读此页面,解释“循环”http://codex.wordpress.org/The_Loop

从你发布的代码片段来看,这似乎就是问题所在。

我在下面发布了一些示例“循环”代码:

代码语言:javascript
复制
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 
<?php /** YOUR CODE HERE **/ ?>
<?php endwhile; else: ?> 
<p><?php
_e('Sorry, no posts matched your criteria.'); ?></p> 
<?php endif; ?>
票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8760079

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档