以前的帖子链接到任意URL

时间:2013-05-29 15:58:37

标签: php wordpress

在我的网站上安装WordPress之前,我创建了几个“帖子”,我希望我的“上一篇文章”链接到这些规则:

  1. 查找Wordpress创建的帖子
  2. 如果不存在Wordpress创建的帖子,请链接到特定网址
  3. 如何实现?

    我尝试过的几件事情都没有用,我很难在线查找信息。这是我的代码:

    <?php define('WP_USE_THEMES', false); get_header(); ?>
    <link href="style.css" rel="stylesheet" type="text/css" />
    
    
    <table id="Table_03" width="855" border="0" cellpadding="0" cellspacing="0">
            <tr style="height:251px">
                <td width="162" valign="top" align="right"><br><br><p>
                <a href="../../../../about.php"><span class="text6">about us  </span><span class="text4">/</span><br>
                </a><p>
                <a href="../../../../culture.php"><span class="text6">our culture  </span><span class="text4">/</span><br>
                </a><p>
                <a href="../../../../partners.php"><span class="text6">partner profiles  </span><span class="text4">/</span><br>
                </a><p>
                <a href="../../../../CEDA.php"><span class="text6">CEDA  </span><span class="text4">/</span><br>
                </a><p>
                <a href="../../../../news.php"><span class="text4">news  </span><span class="text4">/</span><br>
                </a><p>
                </td>
                <td width="59" valign="bottom" align="left"></td>
    
                <td width="532" height="330" valign="top" align="justify"><br><br><p>
                <span class="text4">news  /</span><br>
                    <?php if (have_posts()) : ?>  
                    <?php while (have_posts()) : the_post(); ?>  
                        <div class="post" id="post-<!--?php the_ID(); ?-->">  
                        <div class="entry; text5"><?php single_post_title(); ?></div><p>          
                        <div class="entry; text5"><?php the_content(); ?></div>  
                        </div>  
                    <?php endwhile; ?>
                <td width="102" valign="bottom" align="left"></td>
            </tr>
    </table>
    
    <table id="Table_07" width="855" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td width="221" height="20"></td>
                <td width="532">  
                    <span class="class6" style="float : left; text-align : left;" align="left">
                        <?php previous_post_link('%link', 'previous /', TRUE ); ?></span> 
                    <span class="class6"  style="float : right; text-align : right;" align="right">
                        <?php next_post_link('%link', '/ next', TRUE); ?></span>
                        <?php endif; ?> 
                </td>
    
                <td width="102"></td>
            </tr>
    </table>
    <?php get_footer(); ?>
    

1 个答案:

答案 0 :(得分:1)

get_previous_posts_link()将以前的帖子链接作为字符串返回(如果之前没有任何帖子,则为空):

<?php if (get_previous_posts_link()) {
  previous_post_link('%link', 'previous /', TRUE );
} else {
  echo("static text and link to other URL");
} ?>