SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Specific Tag and Category query withpermalink

    Hello,

    I need to display archive post of a specific category with a specific tag and would like to be able to get the permalink to it, so I can link it to some text if possible. Is this possible?

    Thanks

  2. #2
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Manchester UK
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it is possible, though how many times will you be doing it? You may need to make a custom page with a custom search.
    Hi! I'm Rhys Wynne and I wrote bbPress Complete
    Author+ Premium Wordpress Plugin - Use Code FORUM10 for 10% Off!
    WP Email Capture - Build Your List From Inside Wordpress
    Follow Me on Twitter

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    It would be better to create a custom page template as Rhys stated. You would set up a loop like
    PHP Code:
    <?php
       
       
    if ( have_posts() ) : while ( have_posts() ) : the_post(); 
       if{ 
    in_category(XXX) && get_the_terms($post->ID,'xxx'){
       
    //do stuff
      
    }
      endwhile; endif; 
    ?>
    Ryan B | My Blog | Twitter

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks a lot for the responses and suggestions.

    How would I set it to work with multiple categories and tags. I need each page to have a permalink that is associated with its specific category and associated tags and I was hoping to just use one page template or the archive.php. As of now, I have to create a custom page template with the query you suggested so I can query each
    category and tag. This method I will have to create 100+ page templates and queries. Or I can use

    Code:
    <?php  
    if( is_page('##') { 
        // custom loop ,
    but my php file will be huge. Sorry if this is confusing.

    Thanks again

  6. #6
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    in_category can take an array, so you can do:
    PHP Code:
    if(in_category(array( 9'blue-cheese''Stinky Cheeses' ))){
       echo 
    "You must like cheese!";

    this says if the category is id= 9 OR slug = blue-cheese OR name = Stinky Cheese, then the line, you must like cheese! will be printed on the screen. You could do something like that and have multiple if statements.
    Ryan B | My Blog | Twitter

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You.

  8. #8
    SitePoint Member
    Join Date
    May 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello

    Is it possible to do with current post.
    because the given solution is with specific tag and category.
    I want to show some posts from current category and current tag(or custom taxonomy) on single.php

    Any help will be appreciated.

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by avipr View Post
    Hello

    Is it possible to do with current post.
    because the given solution is with specific tag and category.
    I want to show some posts from current category and current tag(or custom taxonomy) on single.php

    Any help will be appreciated.
    Yes, you can do this with a second loop. Although it would be better to create a specific page to do this on and not use single.php. Check this article out.

  10. #10
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you you have something like this

    PHP Code:
    <?php $wp_query = new WP_Query('cat=10'); // use your category id
    while($custom_query->have_posts()) : $custom_query->the_post(); ?>

        <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
            <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
            <?php the_content(); ?>
                   <?php the_tags(); ?> // gets the tags
                   <?php the_terms(); ?> //gets custom taxonomy, you need to specify which one you want.
        </div>

    <?php endwhile; ?>
    <?php wp_reset_postdata
    (); // reset the query ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •