• wildbuddha

    (@wildbuddha)


    So I am doing a friend’s website and I made the site completely from scratch….I am including the the beginning and end of the loop and am kind of a newb at this so not sure what I’m doing wrong but no matter I do the loop keeps returning the same post…I’ve tried changing the location of wp_reset_query and tried many different query types.

    Here is a copy of my code: (functions.php)

    ob_start();
    error_reporting(0);
    define('WP_USE_THEMES', false);
    require('wordpress/wp-blog-header.php');
    function curPageURL() {
     $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
     return $pageURL;
    }
    function mainMenu(){
    	$indexpage="index.php";
    	if((!$_GET['page']))
    	{echo "<li><a href=\"index.php\" rel=\"home\" class=\"current\">home</a>
            <li><a href=\"index.php?page=philosophy\">philosophy</a></li>
            <li><a href=\"index.php?page=objects\">objects.mobiles</a></li>
            <li><a href=\"index.php?page=mobiles\">children's mobiles</a></li>
            <li><a href=\"index.php?page=orderinformation\">ordering information</a></li>
            <li><a href=\"index.php?page=contactme\">contact me</a></li>";}
    
    $pagename=$_GET['page'];
    if(($pagename==philosophy)){
    echo "<li><a href=\"index.php\" rel=\"home\" >home</a>
            <li><a href=\"index.php?page=philosophy\" class=\"current\">philosophy</a></li>
            <li><a href=\"index.php?page=objects\">objects.mobiles</a></li>
            <li><a href=\"index.php?page=mobiles\">children's mobiles</a></li>
            <li><a href=\"index.php?page=orderinformation\">ordering information</a></li>
            <li><a href=\"index.php?page=contactme\">contact me</a></li>";
    }
    $pagename=$_GET['page'];
    if(($pagename==objects)){
    echo "<li><a href=\"index.php\" rel=\"home\" >home</a>
            <li><a href=\"index.php?page=philosophy\">philosophy</a></li>
            <li><a href=\"index.php?page=objects\" class=\"current\">objects.mobiles</a></li>
            <li><a href=\"index.php?page=mobiles\">children's mobiles</a></li>
            <li><a href=\"index.php?page=orderinformation\">ordering information</a></li>
            <li><a href=\"index.php?page=contactme\">contact me</a></li>";
    }
    $pagename=$_GET['page'];
    if(($pagename==mobiles)){
    echo "<li><a href=\"index.php\" rel=\"home\" >home</a>
            <li><a href=\"index.php?page=philosophy\">philosophy</a></li>
            <li><a href=\"index.php?page=objects\" >objects.mobiles</a></li>
            <li><a href=\"index.php?page=mobiles\" class=\"current\">children's mobiles</a></li>
            <li><a href=\"index.php?page=orderinformation\">ordering information</a></li>
            <li><a href=\"index.php?page=contactme\">contact me</a></li>";
    }
    $pagename=$_GET['page'];
    if(($pagename==orderinformation)){
    echo "<li><a href=\"index.php\" rel=\"home\" >home</a>
            <li><a href=\"index.php?page=philosophy\">philosophy</a></li>
            <li><a href=\"index.php?page=objects\">objects.mobiles</a></li>
            <li><a href=\"index.php?page=mobiles\">children's mobiles</a></li>
            <li><a href=\"index.php?page=orderinformation\" class=\"current\">ordering information</a></li>
            <li><a href=\"index.php?page=contactme\">contact me</a></li>";
    }
    $pagename=$_GET['page'];
    if(($pagename==contactme)){
    echo "<li><a href=\"index.php\" rel=\"home\" >home</a>
            <li><a href=\"index.php?page=philosophy\">philosophy</a></li>
            <li><a href=\"index.php?page=objects\" >objects.mobiles</a></li>
            <li><a href=\"index.php?page=mobiles\">children's mobiles</a></li>
            <li><a href=\"index.php?page=orderinformation\">ordering information</a></li>
            <li><a href=\"index.php?page=contactme\" class=\"current\">contact me</a></li>";
    }
    }
    function wordPressContent(){
    if((!$_GET['page'])){wp_reset_query();
    query_posts( array ( 'category_name' => 'welcome', 'posts_per_page' => 1 ) );
    echo '<div id="content">';
    echo '<h1>';
    echo the_title();
    echo '</h1>';
    echo the_content();
    echo '</div>';wp_reset_query();}
    $pagename=$_GET['page'];
    if(($pagename==philosophy)){wp_reset_query();
    query_posts( array ( 'category_name' => 'about' ) );
    echo '<div id="content">';
    echo '<h1>';
    echo the_title();
    echo '</h1>';
    echo the_content();
    echo '</div>';
    }}
    wp_reset_query();
    
    ?>

    Here is a copy of my code from my index.php file….

    <?php require('functions.php'); ?>
    <!DOCTYPE html>
    <html lang="en" class="no-js">
    <head>
    <script type="text/javascript" src="modernizr-1.7.min.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <?php DynamicMeta();?>
    <link rel="stylesheet" media="screen and (max-width: 950px)" href="css/small.css" />
    <link rel="stylesheet" media="screen and (min-width: 960px)" href="css/style.css" />
    <link rel="stylesheet" media="handheld" href="css/mobile.css" type="text/css">
    </head>
    
    <body>
    <div id="wrapper">
      <header>
       <a href="index.php" rel="home"><canvas id="logo">
         <hgroup> <h1>Noah Crowe</h1>
          <h2>Artist of Objects, Mobiles, Children's Mobiles, Video Editing</h2></hgroup>
        </canvas></a>
        <nav>
        <h1 id="nav">Noah Crowe:Main Naviation</h1>
          <ul>
          	<?php curPageURL();mainMenu();?>
          </ul>
        </nav>
      </header>
      <section>
      <?php wordPressContent();?>
      </section>
    </div>
    </body>
    </html>
    <?php ob_end_flush();?>

    Thanks, in advance, for any help

Viewing 7 replies - 1 through 7 (of 7 total)
  • natehunzaker

    (@natehunzaker)

    Welcome to WordPress! I just have a few comments upon reviewing your code:

    First, I have a quick note about your functions.php file. I would suggest you use the wp_nav_menu() function built in to WordPress. It will automatically generate the navigation menu in a format very similar to what you have created (it’ll even handle child pages). Always let it WordPress the hard work for you!

    I would also highly recommend you remove your “wordpressContent()” function and follow the standard method of implementing the loop within the template file. Again, you won’t have to configure anything and it will automatically pull the content from the relavent post.

    One more note, you shouldn’t have to include the functions.php. WordPress does that for you as well!

    Thread Starter wildbuddha

    (@wildbuddha)

    Hi Nate and thanks for the great welcome!

    In regards to wp_nav_menu function..I am having some issues with styling…I’d like to be able to convert the menu from a ul li list to divs but the php was a little complicated for me so I figured I’d just make my own menu (and stuck to lists anyway!)

    Secondly in regards to the loop, I’m still unsure even after implementing the loop how to get it to show only one page or post? I am trying to use WordPress as more of a CMS than a blog.

    Again, thanks for your help šŸ™‚

    natehunzaker

    (@natehunzaker)

    Not a problem!

    By default, WordPress will use the “page.php” file to serve up pages, and “single.php” to display single posts. When the viewing a page, WordPress has already run a query based upon the query-string in the URL. All you have to do is set up the basic loop within the template.

    In general, I would follow these guidelines as closely as possible.

    For some more hands on learning, take a look at TwentyTen, the default theme that comes with installation. It’s a great place to start for learning WordPress. I’d also recommend a quick read here.

    Thread Starter wildbuddha

    (@wildbuddha)

    Well, thanks to you I got it working! I really needed to be pointed in the right direction of page.php as, at first glance, I was a bit confused.

    I have also taken your advice and implemented wp_nav_menu….now my only issue is getting the menu to refer to other pages on my site without directing me back to WordPress….any suggestions?

    natehunzaker

    (@natehunzaker)

    Just to make sure I answer your question correctly: You’re trying to add a link to a page which isn’t native to your WordPress installation?

    Take a look at the menus section of the WordPress Admin. You can find them under Appearance -> Menus. By default,wp_nav_menu() will use the first custom menu you configure. You’ll need to do some minimal configuring in your functions.php file, but it’ll give you a pretty high level of control over your navigation bar.

    Justin Tadlock has a great guide on it here:
    http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus

    Thread Starter wildbuddha

    (@wildbuddha)

    I think you are correct. I am integrating WordPress into my site via php and the loop so the links wp_nav_menu gives me takes back to the wordpress installation into another directory where wordpress is rather than the same page without the “wordpress/” folder directory. Perhaps I should’ve written back after I had my coffee lol I hope that makes more sense?

    natehunzaker

    (@natehunzaker)

    Haha, not a problem, it’s early. I’m half way through a grande cup of oil myself. You should totally check out that article, Tadlock fully explains what you’re trying to do.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Posts Loop Returning Same Post’ is closed to new replies.