简体   繁体   English

我该如何为wordpress编写代码?

[英]How would I code this for wordpress?

Hello I am fairly new to wordpress. 您好,我对Wordpress还是陌生的。

I was wondering if you guys have any idea on how to display post from wordpress and tweets all in the same 'loop'. 我想知道你们是否对如何在同一“循环”中显示来自wordpress和tweet的帖子有任何想法。

I know It is possible using a if statement that displays a tweet ever nth-wordpress post. 我知道可以使用if语句显示nth-wordpress发布过的推文。 But I would like for both the tweets and the posts to be displayed by date in the same page. 但是,我希望同时在同一页面中按日期显示这些推文和帖子。 any ideas? 有任何想法吗?

so far this is what my page looks like 到目前为止,这是我的页面的样子

<?php 
get_header();

if(have_posts()) {
    while(have_posts()) {
        the_post();

        $post_link = get_permalink(get_the_ID());
        //($beforeString, $afterString, T/F)
        //T/F retun in html-T or in php-F
        the_title('<h1><a href="'.$post_link.'">', '</a></h1>');
        the_content('<p>', '<p>');
        //echo <a href="get_permalink()" 
    }
}
get_footer();
?>

I'd try to get both sources into one array, then sort it and print it out: 我试图将两个源放入一个数组,然后对其进行排序并打印出来:

<?php 
get_header();

//define array
$entrys=array();

//get wp-posts
if(have_posts()) {
    while(have_posts()) {
      the_post();

      $timestamp=//timestamp of post
      $entries[$timestamp]=array(
        'link'=>get_permalink(get_the_ID()),
        'title'=>get_the_title(get_the_ID()),
        'content'=>get_the_content()
      );
    }
}

//insert the twitter-data into the same array here

//sort array
ksort($entries);

//print array
foreach($entries as $e){
  echo '<div class="entry"><h1><a href="'.$e['link'].'">'.$e['title'].'</a></h1>';
  echo '<p>'.$e['content'].'</p>';
  echo '<a href="'.$e['link'].'">Link</a></div>';
}
get_footer();
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM