Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在循环中,我将导航编码放在哪里重要吗?_Php_Wordpress - Fatal编程技术网

Php 在循环中,我将导航编码放在哪里重要吗?

Php 在循环中,我将导航编码放在哪里重要吗?,php,wordpress,Php,Wordpress,我目前正在构建自己的WordPress主题,以“在职学习”为目标,因为我对编写自己的PHP代码还相当陌生 我想在我的博客页面底部放置一组“上一个”和“下一个”链接。我参考了WordPress Codex,其中规定在循环后放置以下代码: <div class="navigation"> <div class="alignleft"><?php previous_posts_link('&laquo; Read Previous Blogs') ?>&l

我目前正在构建自己的WordPress主题,以“在职学习”为目标,因为我对编写自己的PHP代码还相当陌生

我想在我的博客页面底部放置一组“上一个”和“下一个”链接。我参考了WordPress Codex,其中规定在循环后放置以下代码:

<div class="navigation">
 <div class="alignleft"><?php previous_posts_link('&laquo; Read Previous Blogs') ?></div>
 <div class="alignright"><?php next_posts_link('Read More Blogs &raquo;','') ?></div>
 </div>

“在循环之后”是指在“endwhile”语句之后,但在“endif;”之前吗还是在他们一起?我在两种情况下都使用了上述代码,但似乎没有什么不同。只是想知道是否有一个最佳实践等,我已经包括了循环编码,我使用,作为参考,以防我的编码影响任何答案。请忽略[1]、[2]和[3]等数字。我已将这些数字作为注释,供自己使用,我已在单独的文件中创建了自己的注释列表。作为附带问题,这样评论我的编码不会影响性能等:

<?php   
   /*
    =========================================
    Generating the Posts.  The Loop.  (Start)
    =========================================
  */

if ( have_posts() ):                        //[1]
        while( have_posts() ): the_post();      //[2] and [3] 
?>
        <h3><a href="<?php the_permalink(); //[4]?>"><?php the_title(); //[5]?></a></h3> 
        <p><?php the_content(); // [6]?></p> 
        <small>This entry was posted on: <?php the_date('l, jS F Y'); //[7]?> at <?php the_time('g:i a'); //[7]?> and is filed under <?php the_category(); //[7]?></small>
        <small>This Article was written by: <?php the_author_link(); //[7]?></small>
        <div class="post"><?php edit_post_link('Edit','','<strong>|</strong>'); //[8]?>  
        <?php comments_popup_link('Be the first to comment »', 'Just the one comment so far »', '% Comments »', '', 'Comments are Closed for this article.'); //[8]?></div>

<?php 
        endwhile; //[9]
        endif;    //[10]
/*
    =======================================
    Generating the Posts.  The Loop.  (End)
    =======================================
*/
?>
 <div class="navigation">
 <div class="alignleft"><?php previous_posts_link('&laquo; Read Previous Blogs') ?></div>
 <div class="alignright"><?php next_posts_link('Read More Blogs &raquo;','') ?></div>
 </div>

此条目发布于:at,并根据 本文作者:
在while之后(或者在每篇文章下都有主题)和if之前(因此如果没有返回的文章,就不会有主题)。

不,您可以将主题放置在endwhile之间的任意位置endif循环。切勿在endif之后放置查看下面的代码段:

<?php

if ( have_posts() ):    //Checks if posts available 

    while( have_posts() ): the_post();  //loop starts
    ?>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
    <p><?php the_content(); ?></p> 
    <small>This entry was posted on: <?php the_date('l, jS F Y'); ?> at <?php the_time('g:i a'); ?> and is filed under <?php the_category(); ?></small>
    <small>This Article was written by: <?php the_author_link(); ?></small>
    <div class="post"><?php edit_post_link('Edit','','<strong>|</strong>'); //[8]?>  
        <?php comments_popup_link('Be the first to comment »', 'Just the one comment so far »', '% Comments »', '', 'Comments are Closed for this article.');?></div>

        <?php 
            endwhile; //loop end
        ?>
    <div class="navigation">
       <div class="alignleft"><?php previous_posts_link('&laquo; Read Previous Blog Posts') ?></div>
       <div class="alignright"><?php next_posts_link('Read More Blog Posts &raquo;','') ?></div>
   </div> <?php endif;  ?>

此条目发布于:at,并根据 本文作者:
谢谢阿格洛斯·西纳达基斯。非常感谢。感谢您抽出时间来Sajjadur Rahman Sagor。只有两个问题:首先,您声明可以将导航代码放置在endwhile之前的任何位置;循环,但在您修改的代码中,您已将代码保留在endwhile之后;我是不是忽略了什么?其次,您声明在endif;之后永远不会有导航代码;。我尝试将代码“夹在”endwhile之间;和endif;但它没有起作用。我能得到这个“三明治”的唯一方法就是给最后的时间;和endif;他们自己的php标签。这可以吗?或者这会导致问题吗?如果要在endwhite和endif之间添加html,则必须给它们自己的php标记。检查当前代码段