• Resolved Strangeles

    (@strangeles)


    Hello! I’m very new to this and am just learning code. I’ve recently figured out how to allow any page I wish to show posts set to a specific category ID using the following code before the loop:

    <?php
    $catID = 0;
    if (is_page('me')) {
      $catID=11;
    } elseif (is_page('poetry')) {
      $catID=2;
    }
    
    if ($catID) {
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       query_posts("cat=$catID&paged=$paged");
    } ?>
    <?php
    		if ( have_posts( ) ) {
    
    			while ( have_posts( ) ) {

    I would like to know if it would be possible to make the following template which currently shows ALL posts ever made when it’s in use to do the same thing but I’m not finding where to edit or what to change. with pages the loop was easy enough to find from other information I was able to see on this support site but this looks completely different to me.

    The code for that template is here:

    <?php
    /*
    Template Name: list of post
    */
    /* Customize options
    $raindrops_list_of_posts_per_page	= 10;
    $raindrops_list_of_posts_length		= 200;
    $raindrops_list_of_posts_more		= '[...]';
    $raindrops_list_of_posts_use_toggle	= true;
    */
    
    if ( ! defined( 'ABSPATH' ) ) { exit; }
    $raindrops_current_column = raindrops_show_one_column( );
    
    if ( $raindrops_current_column !== false ) {
    
    	add_filter( "raindrops_theme_settings__raindrops_indv_css", "raindrops_color_type_custom" );
    }
    get_header( $raindrops_document_type );
    do_action( 'raindrops_pre_'.basename( __FILE__) );
    raindrops_debug_navitation( __FILE__ );
    ?>
    			<div id="yui-main">
    				<div class="yui-b <?php raindrops_add_class( 'yui-b' ); ?>">
    					<div class="<?php echo raindrops_yui_class_modify( );?>" id="container">
    <?php get_template_part( 'widget', 'sticky' );?>
    						<div class="yui-u first<?php raindrops_add_class( 'yui-u first', true );?>" <?php raindrops_doctype_elements( '', 'role="main"' );?>>
    							<div class="entry page list-of-post-entry">
    <?php
    $query = get_query_var('paged');
    
    if ( have_posts( ) && is_page() && empty( $query ) ) {
    
    	while ( have_posts( ) ) {
    
    		the_post( );
    ?>
    								<div class="entry page">
    									<<?php raindrops_doctype_elements( 'div', 'article' );?> id="post-<?php the_ID( ); ?>" <?php raindrops_post_class( );?>>
    <?php
    		raindrops_entry_title( );
    ?>
    		           						<div class="entry-content">
    <?php
    		raindrops_prepend_entry_content( );
    
    		the_post_thumbnail( 'full','class=page-featured-image' );
    
    		raindrops_entry_content( );
    ?>
                  								<br class="clear" />
    <?php
    		raindrops_append_entry_content( );
    ?>
    										</div>
    									</<?php raindrops_doctype_elements( 'div', 'article' );?>>
    								</div>
    <?php
    	} //end while
    } //end have posts
    ?>
    							</div>
    						<div id="list-of-post">
    <?php
    if( ! empty( $query ) ) {
    
    	raindrops_entry_title( );
    }
    /**
     * List of Posts
     */
    
    	raindrops_list_of_posts();
    ?>
    						</div>
    					</div>
    <?php
    		if ( 3 == raindrops_show_one_column( ) ) {
    ?>
    					<div class="yui-u">
    <?php
    			raindrops_prepend_extra_sidebar( );
    
    			get_sidebar( 'extra' );
    
    			raindrops_append_extra_sidebar( );
    ?>
    					</div>
    <?php
    		} elseif ( $rsidebar_show && false == $raindrops_current_column ) {
    ?>
    			<div class="yui-u">
    <?php
    			raindrops_prepend_extra_sidebar( );
    
    			get_sidebar( 'extra' );
    
    			raindrops_append_extra_sidebar( );
    ?>
    					</div>
    <?php
    		} // end if ( 3 == raindrops_show_one_column( ) )
    ?>
    				</div>
    			</div>
    		</div>
    <?php
    		if ( raindrops_show_one_column( ) !== '1' || false == $raindrops_current_column ) {
    ?>
    		<div class="yui-b">
    <?php
    			//lsidebar start
    			raindrops_prepend_default_sidebar( );
    
    			get_sidebar( 'default' );
    
    			raindrops_append_default_sidebar( );
    ?>
    		</div>
    <?php
    		} //end if ( raindrops_show_one_column( ) !== '1' || false == $raindrops_current_column )
    ?>
    	</div>
    <?php get_footer( $raindrops_document_type ); ?>

    I know this is likely to be rookie info but I’m at a loss and would appreciate whatever information or input you can provide.

    Thank you for your time.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter Strangeles

    (@strangeles)

    My thought is that it would go before here:

    <?php
    $query = get_query_var('paged');
    
    if ( have_posts( ) && is_page() && empty( $query ) ) {
    
    	while ( have_posts( ) ) {
    
    		the_post( );
    ?>

    Any thoughts? Would that even work?

    Hi Strangeles

    list-of-post.php template shows one category.

    For flexibility of function you are using on this page is low, you must do the following.

    Create child theme.

    Example below

    Child theme name:mysite

    Creation of – theme holder
    wp-content/themes/mysite
    Creation of – stylesheet

    style.css is created in the wp-content/themes/mysite/style.css
    The contents are as follows.

    Creation of a style sheet
    style.css

    /*
    Theme Name: mysite
    Author: Your name
    Author URI: http://yoursite.com
    Version: 0.1
    Template:raindrops
    */

    Usually, when making a チャイルド theme, it is explained that the style of a parent theme is imported as follows, but in rained Rops, it is unnecessary.
    the child theme is detected and it imports automatically.

    /* Raindrops No need import rules like below*/
    @import url('../twentyten/style.css');

    make file functions.php
    ver1.200 ~

    add_action( 'switch_theme', 'puddle_uninstall' );
    
    function puddle_uninstall(){
    
        delete_option("raindrops_theme_settings");
    }

    This description is intended to use in a child theme, and change settings of Raindrops, if you uninstall, delete the configuration changes of the parent theme.
    If you did not delete, you may be when you install the new Raindrops, correct, it is not displayed by default.

    Next config for list-of-post

    Copy function raindrops_list_of_posts() at parent/functions.php line:6047

    paste child theme functions.php

    and find below code

    $raindrops_args = array( 'post_status' => 'publish',
    			'post_per_page' => $raindrops_list_of_posts_per_page,
    			'paged' => $query,
    				);

    change below

    $raindrops_args = array( 'post_status' => 'publish',
    			'post_per_page' => $raindrops_list_of_posts_per_page,
    			'paged' => $query,
    			'cat' => 4, //your category
    			);

    copy template from parent / page-templates / list-of-post.php
    to child /page-templates / list-of-post.php

    and customize template if you need.

    Thank you.

    Thread Starter Strangeles

    (@strangeles)

    I appreciate it! I’ll give that a try.

    Thread Starter Strangeles

    (@strangeles)

    No good. Now I’m loading a blank white page. Clearing out the functions file fixed that though. I must have missed something. I switched back to the parent theme for now.

    No good. Now I’m loading a blank white page.

    You should not forget that now, we have been customized.

    For developers, a blank page is a friend.

    important is using the WP_DEBUG, it’s write what error or if it is being out.

    Thread Starter Strangeles

    (@strangeles)

    Like I said, brand new at this as in started yesterday. 🙂 Sorry if I’m not following along as well as you’d expect.

    How would I do that debug?

    Thread Starter Strangeles

    (@strangeles)

    Figured it out.

    Fatal error: Cannot redeclare class raindrops_unique_identifier_walker_nav_menu in /home/USERNAME/public_html/wp-content/themes/raindrops/functions.php on line 5556

    if ( ! function_exists( 'raindrops_nav_menu_primary' ) ) {
    
    	function raindrops_nav_menu_primary( $args = array() ) {
    		global $raindrops_link_unique_text;
    
    		$defaults = array(
    			'theme_location'  => '',
    			'menu'            => '',
    			'container'       => 'div',
    			'container_class' => '',
    			'container_id'    => '',
    			'menu_class'      => 'menu',
    			'menu_id'         => '',
    			'echo'            => true,
    			'fallback_cb'     => 'wp_page_menu',
    			'before'          => '',
    			'after'           => '',
    			'link_before'     => '',
    			'link_after'      => '',
    			'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    			'depth'           => 0,
    			'walker'          => '',
    			'wrap_element_id'  => 'access',
    			'wrap_mobile_class' => 'raindrops-mobile-menu',
    		);
    
    		$args = wp_parse_args( $args, $defaults );
    		$args = apply_filters( 'wp_nav_menu_args', $args );
    
    		if ( "show" == raindrops_warehouse( 'raindrops_show_menu_primary' ) ) {
    
    			if ( $raindrops_link_unique_text == true ) {
    
    				$walker = new raindrops_unique_identifier_walker_nav_menu();
    				$raindrops_nav_menu_primary = wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'echo' => false , 'walker' => $walker ) );
    			} else {
    
    				$raindrops_nav_menu_primary = wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'echo' => false , ) );
    			}
    
    			$template = '<p class="'. $args['wrap_mobile_class']. '">
                                <a href="#access" class="open"><span class="raindrops-nav-menu-expand" title="nav menu expand">Expand</span></a><span class="menu-text">menu</span>
                                <a href="#%1$s" class="close"><span class="raindrops-nav-menu-shrunk" title="nav menu shrunk">Shrunk</span></a>
                                 </p>
                                <%3$s id="'. esc_attr( $args['wrap_element_id'] ). '">
                                %2$s
                                </%3$s>
                                <br class="clear" />';
    
    			do_action( 'raindrops_nav_menu_primary' );
    			$html = sprintf( $template, esc_attr( raindrops_warehouse( 'raindrops_page_width' ) ), $raindrops_nav_menu_primary, raindrops_doctype_elements( 'div', 'nav', false ) );
    			echo apply_filters( 'raindrops_nav_menu_primary_html', $html );
    		} //raindrops_warehouse(  'raindrops_show_menu_primary'  )
    
    	}
    }

    function raindrops_list_of_posts() only.

    Because the wrong range to be copied, the error seems to have occurred.

    Thread Starter Strangeles

    (@strangeles)

    I added the code if that helps clear up more exactly.

    Thread Starter Strangeles

    (@strangeles)

    Thread Starter Strangeles

    (@strangeles)

    Ah! I think I found it. I accidentally deleted one too many characters earlier.

    Parse error: syntax error, unexpected ‘?>’, expecting ‘{‘ in /home/nachoman/public_html/wp-content/themes/raindrops-child/functions.php on line 6048

    That anything to be concerned about or should I turn the debug off?

    Thread Starter Strangeles

    (@strangeles)

    Actually, I think I’ve got most of what I needed. These errors are going to be an excellent way for me to go through and learn PHP. I’m much farther now than I was and getting acquainted with new tools. Thank you for your help. I’ll close this topic.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Editing 'List of Posts' Template to show only one category.’ is closed to new replies.