如何在用户点击博客帖子时创建一个php文件

时间:2016-02-02 11:01:59

标签: php wordpress

我正在使用WordPress上的自定义主题,我目前有一个博客页面显示所有博客帖子,但是当您单击当前重定向到主页的单个帖子时加载的文件。我在网上寻找可重复使用的代码片段,可用于所有博客文章,但没有运气。

以下是我用于博客页面的代码,如何使用ID仅显示已选择的一个帖子?

<div class="content_box active">
                <div class="content_box_content">
                    <h1 style="display:none;"><?php $page->post_title; ?></h1>
                    <p class="para20pt">
                        <span class="orange"><?php echo strtoupper($page->post_title); ?></span>
                    </p>

                    <p class="para34pt">&nbsp;</p>

                    <p class="para72pt">
                        <span class="white"><?php echo strtoupper(get_field('sub_title', $this_page_id)); ?></span>
                        <br>
                        <span class="orange"><?php echo strtoupper(get_field('sub_title2', $this_page_id)); ?></span>
                    </p>

                    <p class="para34pt">&nbsp;</p>

                    <p class="para34pt">
                        <span class="orange"><?php echo get_field('description', $this_page_id); ?></span>
                    </p>
                </div>
                <div class="press_content">
                    <?php 
                    if ( have_posts() )
                    {
                        while ( have_posts() ) : the_post(); 
                        ?>
                        <div class="press_post">
                            <table class="press_post_control close">
                                <tbody><tr>
                                    <td class="press_post_label">
                                        <p class="para20pt">
                                            <span class="orange"><?php the_time(); ?></span></p>
                                        <p class="para34pt">
                                            <span class="white"><?php the_title(); ?></span></p>
                                    </td>
                                    <td class="press_post_container_arrow" align="right">
                                        <div class="press_post_arrow"></div>
                                    </td>
                                </tr>
                            </tbody></table>

                            <div class="press_post_description" style="display: none">
                                <?php
                                $content = $post->post_content;
                                $content = apply_filters('the_content', $content);
                                $content = str_replace(']]>', ']]&gt;', $content);
                                $html = str_get_html($content);

                                $exportString = "";

                                foreach($html->find("p") as $element)
                                {
                                    $exportString .= '<p class="para20pt_press"><span class="orange">' . $element->innertext . '</span></p><p class="para22pt">&nbsp;</p>';
                                }

                                echo $exportString;
                                ?>
                            </div>
                        </div>
                        <?php
                        endwhile;
                    }
                    ?>
                </div>
            </div>
        </div>
    </div>

0 个答案:

没有答案