WordPress.org

Ready to get started?Download WordPress

Forums

Div in certain category in certain position (10 posts)

  1. mircofragomena
    Member
    Posted 7 months ago #

    Hi folks!
    I would like to display a box in a certain category, but it is not working!

    I think that can be more easy for you to understand by viewing the website.

    In this category I would like to display, above the grid, a single box that needs to show a description of the category:
    http://www.mille9e20.com/category/handout/

    So basically it should be like this http://www.mille9e20.com/frati/
    but under the article should be the grid with the projects associated to the category.

    Which is the easier way to do it?
    I just need to put a box on the top of the category (only that category) and add some text/images.

    Thank you so much for all your help as always!

    Cheers

  2. graphical_force
    Member
    Posted 7 months ago #

    Find out what page the category is using and add a div to the code that creates that box. Here is a reference to the Template Hierarchy that may help.

  3. mircofragomena
    Member
    Posted 7 months ago #

    Thanks for your reply.
    But with this method I'll add the div on every category page, and not only in the category "Hand Out"..isn't it?

    Cause I just need to have the div in one specific category that is "Hand out"

  4. graphical_force
    Member
    Posted 7 months ago #

    If you only want to show it on a specific category, use the condition is_category.

  5. mircofragomena
    Member
    Posted 7 months ago #

    YEP!
    It's working!
    Huge thanks!

    Can I decide to display an article inside the is_category function?
    Because the layout that I would like is pretty the same of an article, and it's easier to edit it by the Article page itself instead of coding.

    I'm using this code

    <?php if (is_category('6') || in_category('6')) { ?>
    
    <?php query_posts('p=204'); ?>
    
    <?php } ?>
  6. graphical_force
    Member
    Posted 7 months ago #

    You can do something like if you want one post to show:

    $args = array(
    	'cat' => 6,
            'posts_per_page' => '1'
    );
    
    // The Query
    $the_query = new WP_Query( $args );
    
    // The Loop
    if ( $the_query->have_posts() ) {
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo '
    <li>' . get_the_title() . '</li>
    ';
    	}
    } else {
    	// no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    http://codex.wordpress.org/Class_Reference/WP_Query

  7. mircofragomena
    Member
    Posted 7 months ago #

    I really have to thank you for your time and help!

    The above code is working but I'm just getting the title of the post without any style and content.

    If you, for example, go here http://www.mille9e20.com/hand-out-1-bros/
    you will see a white box with video and text.
    That it's a post that automatically get that style by CSS.

    I would like to have the same box, from a certain post, that appears dynamically with the is_category function to show up the white box + content + style in a certain category.

    Is it possible?

    Really, thank you so much!

  8. graphical_force
    Member
    Posted 7 months ago #

    Try this:

    $args = array(
    	'cat' => 6,
            'posts_per_page' => '1'
    );
    
    // The Query
    $the_query = new WP_Query( $args );
    
    // The Loop
    if ( $the_query->have_posts() ) {
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
                    echo '<div class="boxed">';
    		echo '<h1 class="post-header-title">' . get_the_title() . '</h1>';
                    echo get_the_content();
                    echo '</div>';
    	}
    } else {
    	// no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();
  9. mircofragomena
    Member
    Posted 7 months ago #

    Yes!
    Also this code works, but it doesn't get the information from a ID post but, seems, from the post that I've in the same page.

    What if, for example, would like to load that part of code/content, but from post_ID 123?

    Anyway I have to thank you for everything!

  10. graphical_force
    Member
    Posted 7 months ago #

    You can do this but your now asking about a specific post which is different from asking for posts in a different category.

    You can do try something like this:

    $post = get_post(123);
    $title = $post->post_title;
    $content = $post->post_content;
    
    echo '<div class="boxed">';
    echo '<h1 class="post-header-title">' . $title . '</div>';
    echo $content;
    echo '</div>';

Reply

You must log in to post.

About this Topic