WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Making a static frontpage with a custom query for posts. (3 posts)

  1. chainzor
    Member
    Posted 3 years ago #

    Alright, so yesterday I figured that I need to make my blog with a static frontpage, and a secondary site for the actual blog. However, a new problem arises: i can't seem to put together a custom query that enables me to publish posts of a certain category to my static frontpage. I've had a lot of different attempts on addressing the problem, linking all the code would consume a server or two, none the less i've tried things like copypasta on this, but i just can't get anything to show. : (

    What am i doing wrong here? How do i pull in to info to run The Loop on my static page, (and if you know a real smooth way to exclusevly post from a category, it's probably sneakier than mine :) )

  2. chainzor
    Member
    Posted 3 years ago #

    Hm, there seems to be one problem with my scripting.

    If i instanciate a fresh query:

    <?php  $featured = new WP_Query(); if ($featured->have_posts()) : while ($featured->have_posts()) : $featured->the_post(); ?>
    <?php the_title(); print("<br />"); the_content(); ?>
    <?php endwhile; else: ?>
    <p> Nothin 'ere </p>
    <?php endif; ?>

    Nothing shows.

    So, maybe there's a parameter for the WP_Query() that I'm unaware of? Remember, the script is on a static frontpage, the loop is is on a page called 'Blog'.

  3. chainzor
    Member
    Posted 3 years ago #

    And i finally resolved my own problem. If anyone misses the same thing i do, here's what i lacked:

    <?php $featured->query('cat=1'); ?>

    Apparently, WP_Query doesn't fetch anything untill you specify more. I was unable to figure this from the codex, but an external resources saved my ass.

    Happy hacking!

Topic Closed

This topic has been closed to new replies.

About this Topic