douya1974 2015-08-24 20:08
浏览 53

如何将html添加到php函数中?

I'm using Processwire for my blog.

I know I can call the blog posting loops by using

<?php newsList(); ?>

in index.php but I don't know how to implement html codes in index.php into my blog_functions.php.

Is there any way to do this ?

<div class="blog_item">
  <div class="clearfix"></div>
  <div class="oi_blog_post_meta">
    <div class="oi_blog_post_date">
      <div class="oi_date_d colored">13 July
        <span class="oi_year">2014</span>
      </div>
      <div class="oi_post_cat">
        Java Script</div>
    </div>
    <h5 class="oi_blog_post_title">
                                                                                                        <a href="quisque-consequat-felis-id-lorem-congue/index.html">Quisque Consequat Felis Lorem Congue </a>
                                                                                                    </h5>
    <div class="oi_post_descr_preview">
      Proin sed odio eu turpis sagittis pretium a et metus. Quisque consequat tellus at dolor adipiscing viverra. Cras ligula lectus, viverra tempor ultrices sed, rhoncus quis nulla. Fusce adipiscing, velit nec sodales laoreet,</div>
  </div>
  <div class="oi_post_meta_data_holder">
    <a class="oi_image_link" href="quisque-consequat-felis-id-lorem-congue/index.html">
                                                                                                        <img class="img-responsive" src="
                                                                                                            <?=$config->urls->templates;?>assets/wp-content//uploads/2014/07/photography-movement-13-600x600.jpg" alt="Quisque Consequat Felis Lorem Congue" />
                                                                                                        </a>
    <div class="oi_post_tringle"></div>
  </div>
  <div class="clearfix"></div>

</div>
</div>

and here's my blog_functions.php

function newsList(){

    // Grab the page name from the url

    $thisCategory = wire("page")->name;

    // If the category is not called "news" then output the category name as a selector for the find.

    if($thisCategory !="news") {
        $category = "article_category.name=" . $thisCategory;
    }   

    // Get the news posts - limited to ten for later pagination

    $newsposts = wire("pages")->find("parent=/news-articles/, $category, template=TUT_news, limit=10");

    $out =" ";

    //Loop through the pages

    foreach($newsposts as $newspost){
        $out .="<div class='clearfix'>";
        if($newspost->article_thumbnails){
            $out .="<a href='{$newspost->article_thumbnails->url}' class=''>";
            $out .="<img class='align_left' src='{$newspost->article_thumbnails->getThumb(listingthumb)}'>";
            $out .="</a>";

        }
        $out .="<a href='{$newspost->url}'><h3>{$newspost->title}</h3></a>";
        $out .="<p>{$newspost->article_introtext}</p>";
        $out .="</div>";

    }
    // Pagination

    $out .="<div class='pagination'>";
    $out .= $newsposts->renderPager(array(

                    'nextItemLabel' => "Next",
                    'previousItemLabel' => "Prev",
                    'listMarkup' => "<ul>{out}</ul>",
                    'itemMarkup' => "<li>{out}</li>",
                    'linkMarkup' => "<a href='{url}'>{out}</a>"   

                    ));
    $out .="</div>";

    echo $out;

}
  • 写回答

3条回答 默认 最新

  • doujing1156 2015-08-24 20:14
    关注

    echo the HTML part inside the PHP Script and the browser will parse it as usual.

    <?php
    echo "<html>
                put html contents here.
          </html>";
    ?>
    

    Take care of the " and ' while mixing HTML with PHP.

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致