-4

トグル関数を機能させようとしていますが、基本的な 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

4

2 に答える 2

0

jsまたはjqueryを使用する必要があると思います

$("#groupId").toggle();

とにかくこれを試してください

<div class="group">
<h2><a href="<?php echo $_SERVER['PHP_SELF']."?div=main2&display="; if(isset($_GET['div']) && $_GET['div']=='main2' && isset($_GET['display']) && $_GET['display']=='block'){ echo 'none'; } else { echo 'block'; } ?>" class="trigger">Country 2</a></h2>
<div id='main2' <?php if(isset($_GET['div']) && $_GET['div']=='main2' && isset($_GET['display']) && $_GET['display']=='block') { echo "style='display:none;'"; } else { echo "style='display:block;'"; } ?> class='side-toggle'>
<h2 class="date"><a href="<?php  ?> rel="fancybox" title="the title">The Artist 1 of country 2</a></h2>
<h2 class="date"><a href="<?php  ?> rel="fancybox" title="the title">The Artist 2 of country 2</a></h2>
</div><!--main--></div><!--group-->
于 2012-06-08T07:05:31.447 に答える
0

div で長い間困惑し、上記の順序でカスタム フィールドごとに投稿を印刷するさまざまな方法を試した後、最後の div を出力の先頭に移動すると、他の div の追加と組み合わせてトリックが行われました (他の機能があります)。(だから私は出力を代わりに .

<?php /* Template Name: Count */ ?>
<div class="test">
<?php // 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) {
echo ('<div class="test">'); 

foreach ($rows as $post) {

    setup_postdata($post);
    if ($post->meta_value != $current_value) {
            $current_value = $post->meta_value;
            echo "</div></div><div class='group2'><h3><a class='trigger2' title='Click to expand' rel='nofollow' href='#'>$post->meta_value  +</a></h3><div id='main1' class='side-left-toggle'>";
        }



    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>');

 } //end if rows

?>
</div>
于 2012-06-13T01:03:51.410 に答える