トグル関数を機能させようとしていますが、基本的な PHP の知識しか持っていないため、自分<div>
の をまっすぐにする方法がわかりません... 誰か助けてもらえますか?
私の問題は (jQuery) トグルではなく、Wordpress カスタム投稿タイプ固有のコンテンツをデータベースから取得するために使用される HTML/PHP の組み合わせです。それは私が持っているコードでうまくいきましたが、出力を jQuery 関数に必要な div にラップする方法がわかりません。
最初に:
post_type ごとにすべての meta_value を出力します。この場合、post_type = アーティスト、meta_value = アーティスト_国です。
特定の国に属するすべてのアーティストを次のように印刷しました。
Argentina (artists_country)
- Capitan Tifus (artist title)
- Kapanga (artist title)
これがdivに関する私の問題です。国に属するアーティストのタイトルを (「main1」を使用して) グループ化する必要がありますが、国自体をグループ化する必要はありません。
<div class="group">
<h3><a class="trigger">Country 1</a></h3>
<div id='main' class='side-toggle'>
<h4 class="date"><a href="<?php the_permalink(); ?> rel="fancybox" title="the title">The Artist 1 of that country</a></h4>
<h4 class="date"><a href="<?php the_permalink(); ?> rel="fancybox" title="the title">The Artist 2 of that country</a></h4>
</div><!--main--></div><!--group-->
<div class="group">
<h3><a class="trigger">Country 2</a></h3>
<div id='main1' class='side-toggle'>
<h4 class="date"><a href="<?php the_permalink(); ?> rel="fancybox" title="the title">The Artist 1 of country 2</a></h4>
<h4 class="date"><a href="<?php the_permalink(); ?> rel="fancybox" title="the title">The Artist 2 of country 2</a></h4>
</div><!--main--></div><!--group-->
アーティストをグループ化する方法を見つけようとしています。しかし、どこに div を配置しても、国ごとに 1 人のアーティストが割り当てられ、すべてが複数回ループされます。データベースからコンテンツを取得する方法に関連する問題だと思いますか?
これは私のコードです:
// List posts by a Custom Field's values
$meta_key = 'artists_country'; // The meta_key of the Custom Field
$sql = "
SELECT p.*,m.meta_value
FROM $wpdb->posts p
LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)
WHERE p.post_type = 'artists'
AND p.post_status = 'publish'
AND m.meta_key = '$meta_key'
ORDER BY
m.meta_value ASC,
p.post_title ASC
";
$rows = $wpdb->get_results($sql);
if ($rows) {
foreach ($rows as $post) {
setup_postdata($post);
if ($post->meta_value != $current_value) {
$current_value = $post->meta_value;
echo ('<div class="group">');
echo "<h3><a class='trigger' title='Click to expand' rel='nofollow' href='#'>$post->meta_value +</a></h2>";
echo ("<div id='main1' class='side-toggle'>");
}
// Put code here to display the post
echo ('<h4 class="date">');
echo ('<a href="');
the_permalink();
echo ('" class="postlink" rel="fancybox" title="the title">');
the_title();
echo ('</a>');
echo('</h4>');
}
echo('</div><!--main--> ');echo('</div><!--group--> ');
}
等...
ここにリンクがあります: http://www.musicamestiza.nl/?page_id=4311