"foreach" into the loop
-
hi everyone,
i’m not really a pro but i’m tring to learn and i need an help.
What i want to achieve is a website based on the scroll to function based in the id of the categories. For have this i’m listing the category in the sidebar with the cat-id as link<a href="javascript:void(0)" onClick="goToByScroll('cat- <?php foreach((get_categories()) as $category) { $catid= $category->cat_ID; echo $catid;}?>')"> <?php foreach((get_categories()) as $category) { $catname =$category->cat_name; echo $catname;}?> </a>
this is somehow working.
Then in the main loop there is the difficoult part: I need to have a list of all the post diveded by category:
CATEGORY 1 TITLE
post belongs to cat 1
post belongs to cat 1
CATEGORY 2 TITLE
post belongs to cat 2
post belongs to cat 2and so on. so i tried to build up my loop but is NOT working..
<?php foreach((get_categories()) as $category) { $catid= $category->cat_ID; $catname =$category->cat_name; echo '<div class"categoria" id='$catid'>'; echo '<div class="title">'$catid'</div>'; echo query_posts( array ( '$catname' => 'The Category Name') ); echo if ( have_posts() ) : while ( have_posts() ) : the_post(); echo the_content(); echo endwhile; echo '</div>'; } ?>
thanks for your help!
- The topic ‘"foreach" into the loop’ is closed to new replies.