サポート » 使い方全般 » 同じサーバの別サイトにwordpressの投稿記事を表示

  • 解決済 suberuba

    (@suberuba)


    質問ばかりで申し訳有りません。

    同じサーバの別サイト(hoge.php)にwordpressのa+bの投稿記事一覧を表示させたいと思っています。

    a.最新の投稿記事5件
    b.今日の記事(イベントカレンダーを使用中。今日に該当する記事)5件

    aのみですと単純にRSSで表示できますが、bも表示したい場合はどうするのが良いのか悩んでいます。

    aとbを両方表示するテンプレートを作り、RSSにする場合、下記コードを使ってaのページにbも表示させれば良いと思ったのですが、下記のやり方ですとbのみ表示され、最新記事が表示されなくなりました。

    <?php $current_month = date('m'); ?>
    <?php $current_year = date('Y'); ?>
    <?php $current_day = date('d'); ?>
    <?php query_posts("day=$current_day&year=$current_year&monthnum=$current_month&order=ASC"); ?>

    の下に

    <?php if(have_posts()): while(have_posts()): the_post(); ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php the_content(); ?>
    <?php endwhile; else: ?>
    メッセージ
    <?php endif; ?>

    また、RSSを使わずにもっと簡単な方法があればどなたか教えて頂けますでしょうか?

3件の返信を表示中 - 1 - 3件目 (全3件中)
  • GONSY

    (@digitalix)

    静的ページがPHPなら…

    <?php require(‘./wp-blog-header.php’); ?>

    を先頭に入れてあげれば、Wordpressのタグがそのまま使えます。

    GONSY

    (@digitalix)

    こんな感じで hoge.php(Wordpressのindex.phpと同じディレクトリ)を置けば表示されませんか?

    <?php require(‘./wp-blog-header.php’); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> 
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>hogeトップページ</title>
    ・
    ・
    ・
    ・
    </head>
    
    <body>
    ・
    ・
    ・
    ・
    <div id="news">
    <dl id="areaA">
    <dt>Aのカテゴリ</dt>
    <dd>
    <ul>
    <?php
    $myposts = get_posts('numberposts=5&category=1'); <!-- ID:1/5件 -->
    foreach($myposts as $post) :
    ?>
    <li><?php the_time('Y/m/d') ?>&nbsp;<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    </dd>
    </dl>
    
    <dl id="areaB">
    <dt>Bのカテゴリ</dt>
    <dd>
    <ul>
    <?php
    $myposts = get_posts('numberposts=5&category=3');  <!-- ID:3/5件 -->
    foreach($myposts as $post) :
    ?>
    <li><?php the_time('Y/m/d') ?>&nbsp;<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    </dd>
    </dl>
    </div>
    </body>
    </html>
    トピック投稿者 suberuba

    (@suberuba)

    digitalixさん、こんばんは。うまくいきました。
    RSSをできれば使いたくなかったので助かりました。
    他にも色々応用できるようにもっと勉強したいと思います。
    ありがとうございました!

3件の返信を表示中 - 1 - 3件目 (全3件中)
  • トピック「同じサーバの別サイトにwordpressの投稿記事を表示」には新たに返信することはできません。