Trying to insert custom loop – News Child

Community Forums Forums General Discussion Trying to insert custom loop – News Child

This topic is: resolved

This topic contains 1 reply, has 1 voice, and was last updated by  Scottw 1 year, 5 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #18373

    Scottw
    Participant
    Post count: 7

    Hi,

    I’m stuck and need help with getting a custom loop to display in the news theme (on a template page)  similar to what I do on my site at http://aviationglossary.com/

    I’ve tried a variety of hooks with no success.If I take the code out of the function the  content displays but not in the content area so the loop works but not in the function.

    What am I doing wrong? (I’m fairly new to PHP)

    Template
    get_col($wpdb->prepare("
    SELECT ID
    FROM $wpdb->posts
    WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s
    ORDER BY $wpdb->posts.post_title",$first_char));

    if ($postids) {
    $args=array(
    'post__in' => $postids,
    'orderby' => 'title',
    'order' => 'ASC',
    'post_type' => 'post',//set this to custom post type if applicable
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts'=> 1
    );

    $my_query = null;
    $my_query = new WP_Query($args);

    if( $my_query->have_posts() ) {
    ?>

    have_posts()) : $my_query->the_post(); ?>
    <a href="" rel="bookmark" title=" definition">


    functions.php

    /* url paramter*/
    add_filter('query_vars', 'parameter_queryvars' );

    function parameter_queryvars( $qvars )// Function to be able to pick up mychar value at end of url
    {
    $qvars[] = 'mychar';
    return $qvars;
    }

    • This topic was modified 1 year, 5 months ago by  Scottw.
    • This topic was modified 1 year, 5 months ago by  Scottw.
    • This topic was modified 1 year, 5 months ago by  Scottw.
    • This topic was modified 1 year, 5 months ago by  Scottw.
    #18376

    Scottw
    Participant
    Post count: 7

    Sorry, the code didn’t display.. trying again

    <?php
    remove_action(‘genesis_loop’, ‘genesis_do_loop’);
    //begin glossary code

    add_action( ‘genesis_loop’, ‘custom_loop’ );
    function custom_loop() {

    $first_char = $_GET["mychar"];// gets value of mychar in url
    //get all post IDs for posts beginning with letter equal to value of mychar in url , in title order,
    //display posts

    $postids=$wpdb->get_col($wpdb->prepare(”
    SELECT ID
    FROM $wpdb->posts
    WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s
    ORDER BY $wpdb->posts.post_title”,$first_char));

    if ($postids) {
    $args=array(
    ‘post__in’ => $postids,
    ‘orderby’ => ‘title’,
    ‘order’ => ‘ASC’,
    ‘post_type’ => ‘post’,//set this to custom post type if applicable
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => -1,
    ‘caller_get_posts’=> 1
    );

    $my_query = null;
    $my_query = new WP_Query($args);

    if( $my_query->have_posts() ) {
    ?>

    <h3> <?php echo ‘Aviation Definitions beginning with the letter ‘. strtoupper($first_char);?>
    </h3><?php
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?> definition”><?php the_title();

    ?></a>
    <?php

    endwhile;

    } else
    {
    echo ‘Sorry, no definitions found beginning with the letter ‘. strtoupper($first_char) . ‘, How about adding one?’; ?><?php
    }

    wp_reset_query(); // Restore global post data stomped by the_post().
    }
    } //end glossary

    genesis();

    ?>

     

    Functions.php file

    /* url paramter*/
    add_filter(‘query_vars’, ‘parameter_queryvars’ );

    function parameter_queryvars( $qvars )// Function to be able to pick up mychar value at end of url
    {
    $qvars[] = ‘mychar’;
    return $qvars;
    }

     

     

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

You must be logged in to reply to this topic.