如何使用php在wordpress中以圆圈模式排列div?

时间:2014-12-16 12:40:48

标签: php html css wordpress

在Wordpress中,我想将我的帖子安排在一个圆圈中,现在我将只使用div。我有计算div的坐标的公式。我需要制作div,同时给它们坐标。我该怎么做呢?我知道有可能使用javascript和JQuery,但我真的更喜欢,如果我可以用php做,因为我的研究主题是php。

我真正感兴趣的是这个:

echo "<div class=\"circle\" id=\"<?php $i ?>\" style=\"position: fixed; background-color: red; left: <?php $Xcirclecoordinate?>; top: <?php $Ycirclecoordinate?>;\"";

My wordpress site

<?php 
$args = array('parent' => 0, 'hide_empty' => 0);
$categories = get_categories($args);
$numcats = count($categories);
echo 'numcats= '.$numcats.'<br>';

$radius = 200;
#radius of the circle i want the divs placed in.
$count_posts = wp_count_posts();
#The total number of posts
echo 'count_post= '.$count_posts->publish.'<br>';
#The number of posts published
$circlecenter = array('960','540');
#The center of the screen
echo 'Circlecenter= '.$circlecenter[0].' , '.$circlecenter[1].'<br>';

for ($i=0; $i < $count_posts->publish ; $i++) {
#Looping through the number of posts

$Xcirclecoordinate = $radius*cos((2*M_PI*$i)/$count_posts->publish)+$circlecenter[0];
#Calculating X coordinate
$Ycirclecoordinate = $radius*sin((2*M_PI*$i)/$count_posts->publish)+$circlecenter[1];
#Calculating Y coordinate

echo "<div class=\"circle\" id=\"<?php $i ?>\" style=\"
position: fixed; 
background-color: red;
left: <?php $Xcirclecoordinate?>; 
top: <?php $Ycirclecoordinate?>;\"";
#Trying to place the divs.
}
?>

0 个答案:

没有答案