Thursday 19 May 2016

Show post with WP_Query

<?php have_posts();
$my_query = new WP_Query( 'posts_per_page=6' );
                     while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
                     <li>
<a href="<?php echo $post->post_name; ?>">
<h2><?php the_title();?></h2>
<?php the_content( 'Read more ...' ); ?>
</a>
</li>
<?php endwhile; ?>

how to create dynmic menu in one page theme

<ul class="nav navbar-nav">
<?php
global $post;
$args= array('post_type'=>'page', 'orderby'=>'menu_order', 'posts_par_page'=>'-1','order'=>'ASC');
$myposts= get_posts($args);
foreach ($myposts as $post) :setup_postdata($post); ?>
<li class="dropdown"><a href="#<?php echo $post->post_name; ?>"><?php the_title(); ?></a></li>

                             <?php endforeach; ?>


</ul>