###前提・実現したいこと
トップページのお知らせ・更新履歴一覧に違うブログのお知らせ・更新履歴を一緒に載せたい。
wordpressとwordpress2のブログを作成している者です。
現在3つの方法でお知らせ・更新履歴を載せようとしてますが、上手くいきません。
お知らせのpost_typeはnews_post
更新履歴のpost_typeは'main_post_a','main_post_b','main_post_c'となっています。
①phpmyadminに行きwordpressのwp_postの情報をwordpress2のwp_postの情報とSQL文でUNIONさせる。→更新されない
あと、IDが重複するのでエラーが起きる。
②functions.phpに以下を入力。
/*DB設定を行います。*/ $another_db_name = 'wordpress2'; $another_db_user = 'root'; $another_db_pass = 'dbpass'; $another_db_host = 'localhost'; $another_tb_prefix = 'wp_'; $anoteher_wpdb = new wpdb($another_db_user, $another_db_pass, $another_db_name, $another_db_host); //プレフィックスの設定 $anoteher_wpdb->set_prefix($another_tb_prefix);
参考=https://teratail.com/questions/58785
そのあとindex.phpにどう記入すればいいか分かりません。
<div id="news"> <div id="news_l"><img src="<?php bloginfo('template_directory');?>/img/news.png" alt="お知らせ"></div> <div id="news_r"><a href="/?page_id=121"><img src);?>/img/1.png"></a></div> <div style="clear:both; "></div> <div class="shikiri"></div> <div id="news_inside"> <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;//現在のページ数を設定 $args = array( 'post_type'=>'news_post', 'order'=>'DESC', 'posts_per_page'=>100 ); $wp_query = new WP_Query($args); ?> <?php if ( $wp_query->have_posts() ) : ?> <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?> <?php $news_link_type = get_field('news_post_link_type',$post->ID); ?> <?php $news_link_url = get_field('news_post_link',$post->ID); ?> <?php $news_link_contents = get_field('news_post_contents',$post->ID); ?> <?php $box_backimg++; ?> <?php $post_type = 'news_post'; $post_type_object = get_post_type_object($post_type); $post_type_label = $post_type_object->label; ?> <div class="news_box<?php if($box_backimg == 2){ echo'_gray'; $box_backimg = 0; } ?>"> <div class="data_box"><?php the_time('Y年n月j日') ?> </div> <div class="text_box"> <?php if($news_link_type == '通常リンク'){ ?> <?php echo get_the_term_list($post->ID,'news_post_cat'); ?><a href="<?php the_permalink(); ?>"><?php the_title() ?></a> <?php }elseif($news_link_type == 'URL指定'){ ?> <?php echo get_the_term_list($post->ID,'news_post_cat'); ?><a href="<?php echo $news_link_url; ?>" target="_blank"><?php the_title() ?></a> <?php }else{ ?> <?php echo get_the_term_list($post->ID,'news_post_cat'); ?><?php the_title() ?> <?php } ?> <?php $days=3; $today=date('U'); $entry=get_the_time('U'); $diff1=date('U',($today - $entry))/86400; if ($days > $diff1) { echo '<span style="color:red;">NEW</span>';} ?> </div> <div class="clear"></div> </div> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_postdata(); ?> </div> </div>
③array分を使う→全く分からない......。
以上3点です。
本当に初心者ですが仕事任されましたので・・・。
お知らせが分かれば更新履歴も同じ要領で行けると予測してます。1通りでもいいのでどなたかお力いただけますか?
宜しくお願いします。
あなたの回答
tips
プレビュー