WordPress.org

Ready to get started?Download WordPress

Forums

One post per category (24 posts)

  1. cooldude3663
    Member
    Posted 4 years ago #

    I have tried the other posts but they do nothing. I am a complete noob so I need step by step guide on how to make it so I only have one post show up for only one specific category.

  2. MichaelH
    Member
    Posted 4 years ago #

    Where do you want this limit to take place?

    Which category?

    What theme are you using?

    URL to see the site in question...please.

  3. cooldude3663
    Member
    Posted 4 years ago #

    Umm first of its a NSFW site, I want it to take place on the front page, I want the category to be the second categor which is called Picture of the Day and the theme is Mystique.
    http://wordpress.org/extend/themes/mystique

  4. MichaelH
    Member
    Posted 4 years ago #

    Sorry not clear enough...so will give you some general ideas:

    http://www.google.com/search?q=wordpress+display+featured+category

  5. cooldude3663
    Member
    Posted 4 years ago #

    Well the site is http://www.mysterious-girl.net

    NSFW
    NSFW

  6. MichaelH
    Member
    Posted 4 years ago #

    Yep got that...

  7. cooldude3663
    Member
    Posted 4 years ago #

    Cant find anything in regards to only showing one post for one specific category. I tried using the code you posted for a issue of the same nature, before the loop but to no avail.

  8. MichaelH
    Member
    Posted 4 years ago #

    <?php
      $args=array(
        'cat' => 3,
        'post_type' => post,
        'post_status' => 'publish',
        'showposts' => 1,
        'caller_get_posts'=> 1
        );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
         <?php
        the_content();
        endwhile;
      } //if ($my_query)
    } // foreach
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  9. cooldude3663
    Member
    Posted 4 years ago #

    <?php
     /* Mystique/digitalnature */
     get_header();
    ?>
    
      <!-- main content: primary + sidebar(s) -->
      <div id="main">
       <div id="main-inside">
        <!-- primary content -->
        <div id="primary-content">
    
    <strong><?php
      $args=array(
        'cat' => 2,
        'post_type' => post,
        'post_status' => 'publish',
        'showposts' => 1,
        'caller_get_posts'=> 1
        );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
         <?php
        the_content();
        endwhile;
      } //if ($my_query)
    } // foreach
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?></strong>
          <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div class="page-navigation">

    The bold code is the code you gave me, this code goes before the loop in Single.php correct?

  10. cooldude3663
    Member
    Posted 4 years ago #

    It comes up with an error on line 29 error } expected. Which is: } //if ($my_query)

  11. MichaelH
    Member
    Posted 4 years ago #

    Oops, delete this

    } // foreach
  12. cooldude3663
    Member
    Posted 4 years ago #

    Btw thank you so so so much for your help so far. It is really really appreciated.

  13. MichaelH
    Member
    Posted 4 years ago #

    There is no line 118 there.

  14. MichaelH
    Member
    Posted 4 years ago #

    Also you need to delete one of these sets -- you have two in a row:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div class="page-navigation">
  15. cooldude3663
    Member
    Posted 4 years ago #

    Yeah I was a bit hastey on the ctrl + P there; it seems to have been implemented well, however all the posts of that category are still showing on the page.

  16. cooldude3663
    Member
    Posted 4 years ago #

    <?php
     /* Mystique/digitalnature */
     get_header();
    ?>
    
      <!-- main content: primary + sidebar(s) -->
      <div id="main">
       <div id="main-inside">
        <!-- primary content -->
        <div id="primary-content">
    
    <strong><?php
      $args=array(
        'cat' => 4,
        'post_type' => post,
        'post_status' => 'publish',
        'showposts' => 1,
        'caller_get_posts'=> 1
        );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
         <?php
        the_content();
        endwhile;
      } //if ($my_query)
    
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?></strong>
          <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div class="page-navigation">
              <div class="alignleft"><?php previous_post_link('&laquo; %link') ?></div>
              <div class="alignright"><?php next_post_link('%link &raquo;') ?></div>
              <div class="clear"></div>
            </div>
    
            <!-- post -->
            <div id="post-<?php the_ID(); ?>" <?php if (function_exists("post_class")) post_class(); else print 'class="post"'; ?>>
               <?php if (!get_post_meta($post->ID, 'hide_title', true)): ?><h1 class="title"><?php the_title(); ?></h1><?php endif; ?>
    
                  <div class="post-content clearfix">
        	       <?php the_content(__('Read the rest of this entry &raquo;', 'mystique')); ?>
                  </div>
                  <?php wp_link_pages(array('before' => '<div class="page-navigation"><p><strong>Pages: </strong> ', 'after' => '</p></div>', 'next_or_number' => 'number')); ?>
                  <?php
                  $posttags = get_the_tags();
                  if ($posttags): ?>
                  <div class="post-tags"> <?php the_tags(__('Tags:','mystique').' ', ', ', ''); ?></div>
                  <?php endif; ?>
                  <div class="post-meta">
                        <?php
                         if(get_mystique_option('sharethis') && get_mystique_option('jquery')) $share = true;
                         if ($share) shareThis();
                        ?>
                        <div class="details<?php if($share):?> share<?php endif; ?>">
                        <?php
                        printf(__('This entry was posted on %s at %s, and is filed under %s. Follow any responses to this post through %s.', 'mystique'), get_the_time(get_option('date_format')),get_the_time(get_option('time_format')), get_the_category_list(', '), '<a href="'.get_post_comments_feed_link($post->ID).'" title="RSS 2.0">RSS 2.0</a>');echo ' ';
    
                        if (('open' == $post-> comment_status) && ('open' == $post->ping_status)):
                          // Both Comments and Pings are open
                          printf(__('You can <a%s>leave a response</a> or <a%s>trackback</a> from your own site.', 'mystique'), ' href="#respond"',' href="'.trackback_url('',false).'" rel="trackback"');
    
                          elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)):
                          // Only Pings are Open
                          printf(__('Responses are currently closed, but you can <a%s>trackback</a> from your own site.', 'mystique'), ' href="'.trackback_url('',false).'" rel="trackback"');
    
                          elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)):
                          // Comments are open, Pings are not
                          _e('You can skip to the end and leave a response. Pinging is currently not allowed.','mystique');
    
                          elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)):
                          // Neither Comments, nor Pings are open
                          _e('Both comments and pings are currently closed.','mystique');
                        endif; ?>
                        <?php edit_post_link(__('Edit this entry', 'mystique')); ?>
                        </div>
                        <div class="clear"></div>
    
        		  </div>
    
            </div>
            <!-- /post -->
    
           <?php endwhile; endif; ?>
    
           <?php include(TEMPLATEPATH . '/lib/post-meta.php'); ?>
    
           <?php comments_template(); ?>
    
        </div>
        <!-- /primary content -->
    
        <?php get_sidebar(); ?>
    
        <div class="clear"></div>
    
       </div>
      </div>
      <!-- /main content -->
    
    <?php get_footer(); ?>

    This is my current code.

  17. MichaelH
    Member
    Posted 4 years ago #

    I'm sorry, if it is the single.php, which I used the WordPress Default theme's wp-content/themes/default/single.php, then it would show one post from category 4 and your single post.

  18. cooldude3663
    Member
    Posted 4 years ago #

    I just tried to use the default theme, and used that code in single.php and still nothing.

  19. MichaelH
    Member
    Posted 4 years ago #

    Well you have to actually visit a single post to see it in action. Note it won't be formatted correctly but it will show the stuff.

    I'm guessing you are using the wrong template for where you want to display that info. Review Template Hierarchy for more info.

    And some other examples to grind your teeth with:
    http://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/

  20. cooldude3663
    Member
    Posted 4 years ago #

    I actually think it maybe my installation or something, because I used the default theme and nothing happened. (I added the code in the relevant section when swaping themes.)

  21. digitalnature
    Member
    Posted 4 years ago #

    you can do this without modifying the theme code, assuming you have Mystique 1.20+

    create or edit page/post/whatever, and add this shortcode:
    [query count="1" category_id="4"]

    (if you want it on the home page, set this page as your front page from the Reading menu)

    here you can find more info about [query]

  22. MichaelH
    Member
    Posted 4 years ago #

    Now that's cool.

  23. cooldude3663
    Member
    Posted 4 years ago #

    Ah cool, thanks alot for ALL your help guys. Where do I stick that shortcode though?

  24. digitalnature
    Member
    Posted 4 years ago #

    into a page, post or widget

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags