Listing specific page by slug
-
I would like to create shortcuts to specific pages on my site using a page slug, not an ID, which is how the below code works. Can anyone help? I posted about this months ago, but I got no action.
Here’s a screenshot of what I’m after that just uses static HTML…
https://cl.ly/image/141O2z0W0A11
To be clear, the below code works fine. I just don’t want to use an ID as the live site has a certain set of IDs and then locally I have a different set. And they could possibly change again, so even if I did get them in sync somehow, I’d much rather use a slug. HUGE THANKS to anyone that can help me here. This is a really useful bit of code for anyone that wants something similar on their homepage.
<?php $args=array( 'orderby' =>'parent', 'order' =>'asc', 'post_type' =>'page', 'post__in' => array(2,10,9,7), ); $page_query = new WP_Query($args); ?> <?php while ($page_query->have_posts()) : $page_query->the_post(); ?> <div class="teaser"> <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2> <?php the_excerpt(); ?> </div> <?php endwhile; ?>
- The topic ‘Listing specific page by slug’ is closed to new replies.