Forums

Getting loop inside an iframe (4 posts)

  1. snowboy76
    Member
    Posted 1 year ago #

    Tried to ask this in the "Toubleshooting" forum, got no takers.

    I am building a theme. Modded the index.php file to remove the get_templatepart call. Now I wish to create a page that calls the loop via what would be a copy of the old index.php (minus the header and footer). Want to load this via an iframe in my (now modded) index.php.

    How do I do this? I get all sorts of failures if I take a backup of my index.php and rename it to news.php and try bringing that in via iframe.

    And since someone is going to ask, I think I need the iframe because I'm using a jQuery horz. accordion and if the page reloads upon a click, it resets the accordion or sends to the single.php. By keeping the news.php in an iframe, it loads in there, leaving the page untouched.

    Thanks a head of time.

    Joshua

  2. Indeedle
    Member
    Posted 1 year ago #

    I think you're taking the hard route, the better way would be looking at the jQuery accordion and finding a way to make the changes stick between pages. You could do this by letting it place a cookie remembering the previous state which it then picks on the next page load.

    What specific accordian are you using (since there are a billion of them), you may find it better to alter that then loading wordpress in an iFrame.

  3. snowboy76
    Member
    Posted 1 year ago #

    Thanks Indeedle. But I'm about to throw a wrench into your suggestion. I don't code. I don't know jQuery or javascript or java or PHP or any programing language. None.

    I choose the hAccordian I found at http://letmehaveblog.blogspot.com/2007/10/haccordion-simple-horizontal-accordion.html (note: my browser tells me this is an attack site, but I know its not.) because its baby simple and it uses <div> and not
    ul for its panels (that is important to me) and it will take percentage heights and widths (also important to me).

    Again, if there is a way to fool wordpress into acting like there is a iframe there, I'm fine with that too. But I can't code that. I think this would be a lot easier if I could just get wordpress to load its pages into one <div>. Like some sort of PHP command that said "WordPress, load all files in this div." Then I could put the loop in there everything would be fine. Problem solved.

    Thanks again.

  4. MathSmath
    Member
    Posted 1 year ago #

    The problem is that the files you're trying to load (yourtheme/index.php, for example) can't be loaded directly. In general (with some rare exceptions like the login page), WordPress doesn't work by directly accessing files like that--those are TEMPLATE files that should only be accessed by WordPress itself. Know what I mean?

    If you want to create a single php file that makes available WordPress functions (like queries and a loop), you have to do what's called "bootstrapping" WordPress--loading up the WordPress framework that does all that website-generating magic--then manually creating a query for your loop to use.

    Try putting the following code into a file, then save it as "news.php" in the root of your WP install (alongside wp-login.php, wp-config.php etc.).

    <?
    
    	// Bootstrap WordPress. This makes most WP functions availabe to you now.
    	require( 'wp-load.php' );
    
    	// Your php file is out on its own here, so you need to manually create a query. You can find more about queries and the arguments they accept here: http://codex.wordpress.org/Function_Reference/query_posts
    	$args = array(
    		'post_type' => 'post'
    	);
    	query_posts($args);
    
    	// Begin the loop, just like you normally would.
    	while ( have_posts() ) : the_post();
    
    ?>
    
    		<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    			<h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'mastercard' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
    			<div>
    				<?php the_excerpt(); ?>
    			</div>
    
    <?	endwhile; // end of loop ?>

    Now you can call this file directly (yoursite.com/news.php), and it'll load up a basic loop.

    Hope this helps.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.