• Resolved samdesigns

    (@samdesigns)


    <?php
    $my_query = new WP_Query(‘category_name=featured&showposts=1’);
    if (have_posts()) : while (have_posts()) : the_post();
    update_post_caches($posts);
    $name = the_title(”,”,false);
    $name = ShortenText($name);
    ?>

    • ” title=”<?php the_title(); ?>”><?php echo $name; ?>
    • <?php endwhile; endif; ?>

      I use that script to grab all the post titles and links in the featured category, then put them in a list. It works fine on index.php – but when it’s on any other page – it just grabs all the pages from the current category, or the current page etc.

      Anyway to make it so it works on every page?

      Thank you,
      Sam.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter samdesigns

    (@samdesigns)

    Ignore " title="<?php the_title(); ?>"><?php echo $name; ?>

    It was html, but i don’t seem to be able to edit it. It doesn’t make any difference.

    Thread Starter samdesigns

    (@samdesigns)

    Also, i looked into the wordpress MySQL, i was surprised when i found nothing about Categories (Even when there were different categories, they all had value 0 – where i could find no link between number and name). As i was going to write my own mysql code if all else failed.

    I really need help with my first post.

    Modify your if/while lines to:

    if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();

    The post_category column in the posts table is a holdover from when WordPress only supported 1 category per post. These days category data shares space with link categories and tags in the terms, term_taxonomy and term_relationships tables.

    Thread Starter samdesigns

    (@samdesigns)

    Thank you very much for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WP-Query different on various pages [Problem]’ is closed to new replies.