Support » Plugins » Displaying cats with same title as page

  • Hi,

    This is the second time I have to do this, so I wanted to see if there is a less hacky way than what I’ve conjured:

    if (preg_match('/about/',$query_string)) {

    ..basically grabbing the url and chopping out the page slug to use for my cat query.


Viewing 5 replies - 1 through 5 (of 5 total)
  • alvarix,

    Can you explain a little more? If you’re able to do this I assume you can just use a WP query as well.

    <?php $my_query = new WP_Query('cat=6&showposts=1');
             while ($my_query->have_posts()) : $my_query->the_post();
             $do_not_duplicate = $post->ID; ?>

    Why doesn’t this work?



    Thanks, you know a lot more about wordpress than I do it seems, but I don’t think you are solving my problem. In your example I would need to grab cat=6 dynamically from the current page, which means I cant use the numeric ids, rather the slug strings. Eg:

    I have a page named about that I want to automatically display posts in the about category as well. Hence the chopping of the url in my example, to parse the about page url to create the category query.

    Ideally the solution would work across multiple page/cat intersections, ie as a template for multiple pages.




    I’m a little confused as to what you are try to do. I understand you are checking the URL to retrieve a specific category. I have resorted to this in an instance where the only difference between the pages was the URL but I wouldn’t recommend this as an option if at all possible to avoid it.

    Your example didn’t display.

    If you have a category named About and a page named About why not call on posts specifically in the About category on the About template? It doesn’t seem necessary to use preg_match in this case because the page is so specific.

    <?php $my_query = new WP_Query('category_name=about&showposts=1');
             while ($my_query->have_posts()) : $my_query->the_post();
             $do_not_duplicate = $post->ID; ?>


    The reason for the pregmatch is because this query occurs on a template that spans several pages (ie. about, video, books) so I need to create the query dynamically.




Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Displaying cats with same title as page’ is closed to new replies.