Re: カスタム投稿
永らくありがとうございました › フォーラム › 使い方全般 › カスタム投稿 › Re: カスタム投稿
2013 年 12 月 13 日 10:01 AM
#3446
ゲスト
toemon様、ご無沙汰しています。
今更ではございますが、色々な試行錯誤の結果、目標に近い表示
を得る事が出来ましたので、稚拙なコード(?)ではありますが
投稿いたします。
カスタムブロックについて
カスタム投稿は2種類「movie」と「hobby」
カスタムフィールドで必要なフィールド名は「weather」
として、XOOPSのトップページの中央部分に
タイトル
記事の一部分(200文字まで)
の形で表示できました。
<code><?php<br /> global $wp_query;<br /> get_posts(array_merge(<br /> array(<br /> 'post_type' => array('movie','hobby') ),<br /> $wp_query->query<br /> ));<br /> ?><br /> <br /> <?php if(have_posts()) : while (have_posts()) : the_post(); ?><br /> <br /> <div style="margin-bottom : 10px"><br /> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'xpress'), the_title_attribute('echo=0')); ?>"><br /> <b><?php the_title(); ?></b> <!-- 記事タイトル(太字) --><br /> <br><br /> </a><br /> <div style="margin-left:20px;"><br /> <?php<br /> $pattern = '/(^.{200})(.+)/u'; <!-- 200文字制限 --><br /> $subject = post_custom('weather');<br /> $matches = array();<br /> preg_match($pattern, $subject , $matches);<br /> if ($matches[2] != '') {<br /> $out = $matches[1] . '';<br /> } else {<br /> $out = $subject;<br /> }<br /> echo($out);<br /> ?><br /> </div><br /> </div><br /> <?php endwhile; endif; ?></code>
本当にお世話になりました。
重ねて、感謝申し上げます。