对WP来说很新。我正在尝试创建帖子的永久链接。这是生成链接的代码:
$page_id = get_the_ID();
switch($page_id){
case 6:
$programming_posts = get_posts('category=9');
break;
case 85:
$programming_posts = get_posts('category=13');
break;
case 78:
$programming_posts = get_posts('category=11');
break;
case 91:
$programming_posts = get_posts('category=15');
break;
case 83:
$programming_posts = get_posts('category=12');
break;
case 69:
$programming_posts = get_posts('category=10');
break;
}
?>
<div class="span6" id="content">
<div class="row-fluid">
<?php $i = 1; foreach($programming_posts as $key => $post){
/*Condition that creates a new row each two posts.*/
if($i % 2 == 0){ ?>
<div class="row-fluid" id="temporary-fix">
<?php } ?>
<div class="span6 well well-small" id="post-preview">
<?php echo $post->post_excerpt;?>
<br />
<div class="pull-right">
<a href="<?php echo get_permalink($post->ID);?>"><b>Go to post</b></a>
</div>
</div>
<?php if($i % 2 == 0){ ?>
</div> <!-- Closes the row-fluid div element. -->
<?php $i++; } if($i > 8) break; } //Foreach loop end.?>
</div>
</div>
也许不是练习,但正如我在开始时所说的那样,我是 WP 新手。Var dumping get_permalink($post->ID) 生成正确的 url 字符串,据我了解,WP 将使用 single.php 发布帖子,并且我将一些任意 HTML 与页眉、“循环”和页脚放在一起,但链接似乎已损坏。
single.php 内的代码
<?php
get_header();
if ( have_posts() ) while ( have_posts() ) { the_post(); the_content();?>
<p>This is some arbitrary text</p>
<?php }
get_footer();
?>
我究竟做错了什么?