Grow your CSS skills. Land your dream job.

WordPress Loop and Structuring

  • # December 1, 2008 at 3:23 pm

    Hi Guys,

    So this is the structure I want to go with for my site, chadwik.us.

    I need my page to be structured as follows:

    Home – (Static Page that has recent articles from my blog page posted on it)

    My Work – (Uses the loop to grab articles about recent projects that I have done)

    My Services – (Uses page.php)

    Blog – (Uses the loop to grab articles that everything but what is in My Work)

    Contact – (Uses a special_template.php so I can include forms).

    I have been successful up to the pages that I want to use the loop on.

    What is the best way of going about this? So far I have tried creating special_templates that has the loop code in them for the two pages that I need to use it on. The problem I am seeing is that it is recognizing that it is a page and using both page.php and the special_template. How do I get this to work without having my url’s something like chadwick.us/categories/blog. You can see I am currently trying to query in certain categories but it is doing something weird and list all the posts at the top and what ever is in those posts at the bottom. Any help would be awesome.

    Thanks

    # December 1, 2008 at 6:25 pm

    This is what I would do.

    Install wordpress in the root directory of the site.

    Create a page called "blog" with a permalink of /blog/.

    Create another page called "homepage".

    Under settings > reading change your front page to be a static page and choose homepage, and set the posts page to be the blog page you created.

    Now you can do anything you want with that homepage, since it’s literally a page. If you want recent posts on it, I’d use the SimplePie WordPress plugin or something like that.

    At /blog, now is using your index.php file, to show recent posts as well.

    Now you want to make a category to use just for projects, so do that, and note the ID of the category. To skip over these posts in /blog, alter your loop like this:

    Code:
    < ?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>


    < ?php if (in_category('3')) continue; ?>

    Just make "3" into whatever the category ID is for your recent work.

    Now to have a page that is JUST posts in that category, you can use a wordpress generated category URL, like http://yoursite.com/category/recent-work

    If you hate the idea of a URL like that, then what I would do is create a new page at /recent-work and use that same SimplePie plugin to pull recent articles from http://yoursite.com/category/recent-work/feed, which would be the RSS feed for only that category.

    Maybe not the best solutions ever, there probably is ways to do it with only WP functions, but this is how I usually roll.

    # December 1, 2008 at 7:46 pm

    Thanks Chris,

    I also found this to work too which gets around the whole long URL (Or at least that’s the way I got it to work).

    Create a page called Blog or any page that you want to use the loop on. Create a new .php template and use it on that page with this code in it. I am now looking at the posts through Firebug to style them accordingly

    Code:
    < ?php
    /*
    Template Name: BlogPage
    */
    ?>

    < ?php get_header(); ?>

    < ?php query_posts('category_name=article_test&showposts=10'); ?>

    < ?php $posts = get_posts('category_name=article_test'); foreach ($posts as $post) : start_wp(); ?>

    < ?php the_content(); ?>

    < ?php the_title(); ?>

    < ?php endforeach; ?>

    < ?php get_sidebar(); ?>

    < ?php get_footer(); ?>

    # December 2, 2008 at 12:24 pm

    you can take the loop outside as well.

    this was my post somewhere else:

    I have wordpress on a client site within a resources directory, but the main page (not in that directory) has a link to an excerpt to the latest post.

    in your main html page you want to show the wordpress stuff add this PHP (to the very top) and rename the HTML page to a PHP page:

    Code:
    < ?php
    // Include WordPress
    define('WP_USE_THEMES', false);
    require('/directory_to_your_wordpress_header.php/wordpress/wp-blog-header.php');
    query_posts('showposts=1');
    ?>

    then where-ever you want the excerpt on your page place this code:

    Code:

    < ?php while (have_posts()): the_post(); ?>

    < ?php the_title(); ?>

    < ?php the_excerpt(); ?>

    ” class=”text1″>Read more…

    < ?php endwhile; ?>

    it took me nearly 3 weeks to find out how to link wordpress outwith the main loop

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".