开发者

Noob Question: Wordpress Looping

开发者 https://www.devze.com 2022-12-25 17:27 出处:网络
Can someone give me an essential Wordpress Loop and explain to me what\'s happening with it? I\'d like to put together some templates, but I don\'t do well with blackboxing. In other words, I\'m fully

Can someone give me an essential Wordpress Loop and explain to me what's happening with it? I'd like to put together some templates, but I don't do well with blackboxing. In other words, I'm fully capable of writing my own CMS, but when it comes to using someone else's 开发者_StackOverflow中文版and its arbitrary rules, I'm completely at a loss, and I just can't get my head around the standard loop Wordpress uses. Thanks for your patient guidance.


There is a really nice tutorial from SpoonGraphics describing how to build your own theme for wordpress and explaining the required coding. It also covers the standard wordpress loop and explains how to build around it:

http://www.blog.spoongraphics.co.uk/tutorials/how-to-build-a-custom-wordpress-theme-from-scratch


You might want to start with reading the codex article on the The_Loop. Beyond reviewing their loop documentation, reading up on the various template tags should be helpful to you as well.

Begins the loop:

<?php if ( $posts ) : foreach ( $posts as $post ) : start_wp(); ?>

Generates a div container marked up with a post-specific id and post_class adds additionally CSS classes depending on the categories/tags/etc of the post.

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

Displays the post title as a permalink to the post.

<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2

Displays some the post's publish date with a link to other posts by the same author.

 <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>

Pulls the full contents of the post, wrapped in a div container to ease CSS styling.

Closes the loop, and displays a message if no posts were found.

<?php endforeach; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p> 
<?php endif; ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号