ThemeShaper Forums » Thematic

[closed]

How to bring this function only to specific pages?

(8 posts)
  • Started 4 years ago by Aaron
  • Latest reply from feemcgill
  • This topic is not resolved
  1. Well it seems to me like a basic php question: This function works very well to add category posts to specific pages while still displaying the page content above.

    But I want this function to only be loaded on three specific pages. On all other pages it should not be called, otherwise it produces a second identical loop.

    I tried some "if (is_page(153) || (is_page(12) || (is_page(7)) {........}" things, but all if constructions lead to a blank white page...

    please help, how do I wrap it into some "if" to get it work?

    function kraeuter_page_loop() {
    
    		if (is_page(153)) {
    		query_posts("cat=9&showposts=10");
    		} elseif (is_page(12)) {
    		query_posts("cat=4&showposts=10");
    		} elseif (is_page(7)) {
    		query_posts("cat=3&showposts=10");
    		} else {}
    		/* Count the number of posts so we can insert a widgetized area */
    		$count = 1;
    		while ( have_posts() ) : the_post() ?>
    
    			<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
    			<b>CUSTOM CONTENT</b>
        			<?php thematic_postheader(); ?>
    				<div class="entry-content">
    <?php // thematic_content(); ?>
    
    <?php 
    
    	if (is_home() || is_front_page()) {
    		$content = 'full';
    	} elseif (is_single()) {
    		$content = 'full';
    	} elseif (is_page()) {
    		$content = 'full';
    	} elseif (is_tag()) {
    		$content = 'full';
    	} elseif (is_search()) {
    		$content = 'full';
    	} elseif (is_category()) {
    		$content = 'full';
    	} elseif (is_author()) {
    		$content = 'full';
    	} elseif (is_archive()) {
    		$content = 'full';
    	}
    
    	if ( strtolower($content) == 'full' ) {
    		$post = get_the_content(more_text());
    		$post = apply_filters('the_content', $post);
    		$post = str_replace(']]>', ']]>', $post);
    	} elseif ( strtolower($content) == 'excerpt') {
    		$post = get_the_excerpt();
    	} elseif ( strtolower($content) == 'none') {
    	} else {
    		$post = get_the_content(more_text());
    		$post = apply_filters('the_content', $post);
    		$post = str_replace(']]>', ']]>', $post);
    	}
    	echo apply_filters('thematic_post', $post);
     ?> 
    
    				<?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    				</div>
    				<?php thematic_postfooter(); ?>
    			</div><!-- .post -->
    
    				<?php comments_template();
    
    				if ($count==$thm_insert_position) {
    						get_sidebar('index-insert');
    				}
    				$count = $count + 1;
    		endwhile;
    	}	
    
    add_action('thematic_below_indexloop', 'kraeuter_page_loop');
    Posted 4 years ago #
  2. Hi Aaron,

    That is the wrong hook for pages try this and see if it's what you were trying to accomplish:

    function kraeuter_page_loop() {
    
    	if (is_page(2)) {
    		query_posts("cat=9&showposts=10");
    		thematic_index_loop();
    		} elseif (is_page(12)) {
    		query_posts("cat=4&showposts=10");
    		thematic_index_loop();
    		} elseif (is_page(7)) {
    		query_posts("cat=3&showposts=10");
    		thematic_index_loop();
    		} else {
    		return;
    	}
    }
    add_action('thematic_abovepagebottom', 'kraeuter_page_loop' );

    -Gene

    Posted 4 years ago #
  3. Hey Gene genius!

    It was the right hook but I had a bad function architecture. You arranged the if clause very elegantly and it started to work!
    Finally this one worked for me:

    function childtheme_second_loop() {
    
    	if (is_page(153)) {
    		query_posts("cat=9&showposts=10");
    		thematic_index_loop();
    		} elseif (is_page(12)) {
    		query_posts("cat=4&showposts=10");
    		thematic_index_loop();
    		} elseif (is_page(7)) {
    		query_posts("cat=3&showposts=10");
    		thematic_index_loop();
    		} else {
    		return;
    	}
    }
    add_action('thematic_below_indexloop', 'childtheme_second_loop' );

    Thanks!

    Full description is here:
    http://forums.themeshaper.com/topic/how-to-display-posts-from-categories-on-pages-using-a-second-loop#post-9021

    Posted 4 years ago #
  4. feemcgill
    Member

    Thanks for this everyone.. I have a problem. I want the posts to appear inside the container div or at the bottom of the content div; however with the code below my sidebar disappears. Any suggestions?

    function childtheme_second_loop() {

    if (is_page(103)) {
    query_posts("cat=11&showposts=10");
    thematic_index_loop();
    } else {
    return;
    }
    }
    add_action('thematic_belowcontent', 'childtheme_second_loop' );

    function fullpostr($content) {
    if (is_page()) {
    $content= 'full';}
    }
    add_filter('thematic_content', 'fullpostr');

    Posted 3 years ago #
  5. middlesister
    Member

    And the page 103 is not using a fullwidth template or anything like that?

    Posted 3 years ago #
  6. feemcgill
    Member

    No different templates. I just simply added that code to functions.php. When I hook the code to thematic_abovefooter, the sidebar is there.. but I want to hook it to below content like in the code above.. when I do this the sidebar disappears.

    Posted 3 years ago #
  7. middlesister
    Member

    If I paste the code into a test install, it works for me - the loop shows inside #container but after #content. The sidebar is still there.
    Do you have anything else hooked to thematic_belowcontent? Or are you filtering thematic_sidebar at some point?
    Could you maybe provide a link to your site?

    Posted 3 years ago #
  8. feemcgill
    Member

    Thanks Middlesister.. sorry for the late reply.. Here's a link: http://adamgoldbergdilettante.com/listen/the-goldberg-sisters/

    The code in question is not active right now.. but let me know if you see anything going on!

    I really appreciate it.

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.