Wordpress:Index.php到Single.php页面断开连接

时间:2011-02-03 19:34:26

标签: wordpress

我为我对这样一个关键概念缺乏了解而道歉,但最终会陷入困境!

这是我的index.php页面上的代码。我希望每个投资组合“项目”链接到它的相应single.php页面,该页面将显示更多信息/图像。

<?php 
    $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 12)); 
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php   
    $custom = get_post_custom($post->ID);
    $screenshot_url = $custom["screenshot_url"][0];
    $website_url = $custom["website_url"][0];
?>
    <div class="item">
    <a href="<?=$website_url?>"><?php the_post_thumbnail(); ?> </a>

    <h3><?php the_title(); ?></h3>
    <p><?php the_excerpt(); ?></p>
    <p><a href="<?php echo get_permalink(ID); ?>">This is a link</a></p>
    <p><a href="<?php the_permalink(); ?>">Read more</a></p>
</div>
    <?php endwhile; ?>  

这是我的single.php页面上的代码。我认为我的循环线是错误的,因为无论我在主页上点击什么项目,它都会拉入相同的一个条目,但我不知道它们应该是什么。

<?php $loop = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 1)); 
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php   
    $custom = get_post_custom($post->ID);
    $screenshot_url = $custom["screenshot_url"][0];
    $website_url = $custom["website_url"][0];
?>
    <div class="left">
    <a href="<?=$website_url?>"> </a>
    <h3><?php the_title(); ?></h3>
    <p><?php the_content(); ?></p>

</div>
    <?php endwhile; ?>  

对于这个Wordpress新手的任何提示将不胜感激!注意:我知道基本的HTML和CSS,但PHP对我来说是一个新概念。

1 个答案:

答案 0 :(得分:1)

您仍然使用循环来加载当前帖子的_post(),您只需要运行自定义查询。

尝试:

<?php global $wp_query; ?>
                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                <?php   
                    $custom = get_post_custom($post->ID);
                    $screenshot_url = $custom["screenshot_url"][0];
                    $website_url = $custom["website_url"][0];
                ?>
                    <div class="left">
                    <a href="<?=$website_url?>"> </a>
                    <h3><?php the_title(); ?></h3>
                    <p><?php the_content(); ?></p>

                </div>
                    <?php endwhile; ?>
                <?php endif; ?>
相关问题