Forums

Formatting queries (5 posts)

  1. Lazurus
    Member
    Posted 4 years ago #

    Hi all,

    I'm trying to display all posts alphabetically. I've managed to work something out, but can't figure out how to get it formatted nicely.


    < ?php if (have_posts()) :
    while (have_posts()) : the_post();
    the_title();
    endwhile;
    endif;
    query_posts('category_id=1&orderby=title&order=ASC&posts_per_page=-1');
    if (have_posts()) :
    while (have_posts()) : the_post();
    the_title();
    endwhile;
    endif; ?>

    I just want to break or li after each result, and have each result linked. Possible? Plausible? Too much like work?

    Cheers!

  2. skippy
    Member
    Posted 4 years ago #

    <?php
    query_posts('category_id=1&orderby=title&order=ASC&posts_per_page=-1');
    if (have_posts()) :
    while (have_posts()) : the_post();
    ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
    <?php
    endwhile;
    endif; ?>

    Note: completely untested.

  3. Lazurus
    Member
    Posted 4 years ago #

    Sweet... but...

    Parse error: parse error, unexpected $ in /home/music20/public_html/wp/wp-content/plugins/runphp.php(96) : eval()’d code on line 5

    All Reviews

    Parse error: parse error, unexpected T_ENDWHILE in /home/music20/public_html/wp/wp-content/plugins/runphp.php(96) : eval()’d code on line 2

    <b>A little more background...</b>
    Using the runphp plugin to toss this on a page. All Reviews is the page title.

    Ta!

  4. Beel
    Member
    Posted 4 years ago #

    The code looks good and should work. Create a page template for the All Reviews page and put it there.

  5. Lazurus
    Member
    Posted 4 years ago #

    Ah, I understand.

    Okay, if anyone is searching for this, here is the solution, nicely packaged.

    1. Create a file on your local computer called single.php. Dump the following into that file:
    <?php /*
    Template Name: Single Page
    */
    ?>

    <?php get_header(); ?>
    <?php get_sidebar(); ?>

    <div id="content">
    <?php the_content(); ?>
    <?php
    query_posts('category_id=1&orderby=title&order=ASC&posts_per_page=-1');
    if (have_posts()) :
    while (have_posts()) : the_post();
    ?>
    "><?php the_title(); ?>
    <?php
    endwhile;
    endif; ?>
    </div>

    <?php get_footer(); ?>

    Save the file and upload it to your themes dir in wp-content.

    2. Create a blank page (write --> pages). Set the template to be this page.

    3. Voila. It runs. Apply whatever formatting you want.

    Thanks for the help Beel and Skippy.

Topic Closed

This topic has been closed to new replies.

About this Topic