what I’ve never understood about wordpress
-
I have never understood this part of WordPress use, even though I have developed many templates for clients. I love WP.
There seems to be two different ways to access post data. One way that the default theme does it, and the way that I eventually end up doing it which feels like a hack but eventually gets me all the data I want.
For example, the default theme’s page.php main loop looks like this:
<div id="content" class="narrowcolumn"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><?php the_title(); ?></h2> <div class="entry"> <?php the_content('<p class="serif">Read the rest of this page » '); ?> <?php wp_link_pages(array('before' => '<strong>Pages:</strong> ', 'after' => ' ', 'next_or_number' => 'number')); ?> </div> </div> <?php endwhile; endif; ?> <?php edit_post_link('Edit this entry.', '', ' '); ?> </div>
Okay, great. But now what if I want to get the page’s slug name such as is stored in $post->page_name if I use get_posts and then a foreach, like so:
<ul> <?php global $post; $myposts = get_posts('numberposts=5&offset=1&category=1'); foreach($myposts as $post) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>
Now $post has all that awesome useful data in it, but this means rewriting all templates all the time, which is a pain. Is there an easy way to get that data inside the first style of page listing?
- The topic ‘what I’ve never understood about wordpress’ is closed to new replies.