SamDesigns
Member
Posted 4 years ago #
<?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.
SamDesigns
Member
Posted 4 years ago #
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.
SamDesigns
Member
Posted 4 years ago #
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.
SamDesigns
Member
Posted 4 years ago #
Thank you very much for your help.