Grow your CSS skills. Land your dream job.

tough question about WordPress

  • # April 3, 2013 at 11:14 pm

    I have been trying for months to make a one page WordPress site and have been having a lot of problems trying to do it. I just can’t figure out the best way to make this site. I run into one problem after another. I need to get every post and every page into an unordered list on the homepage so that when you push the nav button for a page or post, it scrolls into view. This would be really easy with html but I am having a heck of a time doing it with WordPress. I can not find one article on how to make a one page wordpress site. Do you have any ideas on this matter of how this could be achieved?

    # April 3, 2013 at 11:28 pm

    To clarify, you want a list of links for all pages and all posts. When you click on those links, you want the content to scroll into view, correct?

    # April 3, 2013 at 11:41 pm

    This is exactly what I am trying to accomplish. This is the site I am working on

    http://www.rc-hc.com/mafloral

    The problem with it is that I have to go to setting -> reading and set the post count to 999999999 in order to get all posts and pages to show up. Right now the site is set up to run from the index.php. I am using a loop to get posts and page templates. I just don’t know that it is the best way to get them because it also affects the next and previous posts links that should show on the blog. I did have pagination working at one point but for some unknown reason, it just stopped working.

    I did try to get the posts and pages using ajax but that turned into a massive headache as there are zero articles on how to achieve this. I had to make my own custom walker for the nav so that it would add the #! characters into the navigation which the site needs in order to scroll the pages into view.

    I tried many loops using different functions like get_pages() but that would not return page templates. I tried just using the template hierarchy but that doesn’t work either. I tried using pre_get_posts to return the pages to the homepage but again, for some reason, it would ignore templates. I was hoping to find a way to get all the posts and pages that are listed in the nav so that only those posts and pages would load into the site so it wouldn’t take forever to load but I can’t figure it out. This is how I am doing the main loop now. After 3 months of trying



      < ?php

      $args = array(
      'post_type' => 'page'
      );

      $page_query = new WP_Query( $args );

      if ( $page_query->have_posts() ) : while ( $page_query->have_posts() ) : $page_query->the_post();
      $template = get_post_meta( $post->ID, '_wp_page_template', true );

      // If the page doesn't have any template assigned - display the default page template
      if ( $template == 'default' ) { ?>



    • < ?php the_title();?>



      < ?php the_content(); ?>





    • < ?php } else {

      //var_dump($template);
      ?>
    • < ?php
      include( $template );
      } ?>
    • < ?php
      endwhile;
      endif;
      ?>





    # April 4, 2013 at 1:56 am

    Your $args are okay, but I’m confused about why you are calling for page templates. You’ll only get one shot at formatting the data within this loop.

    Maybe you could try:

    < ?php is_page_template($template); ?>

    http://codex.wordpress.org/Conditional_Tags#Is_a_Page_Template

    Then you could run something like:

    if is_page_template (‘template1.php’)

    < ?php the_title();?>

    < -- ...etc. -->

    else if is_page_template (‘template2.php’)

    < ?php the_title();?>

    < -- ...etc. -->

    and so on.

    # April 4, 2013 at 1:59 am

    Guess I should try to figure out proper formatting for this forum. :)

    # April 4, 2013 at 12:28 pm

    Fixed the formatting for ya.

    # April 4, 2013 at 12:44 pm

    Thanks!

    # April 4, 2013 at 7:13 pm

    I am calling for page templates because the page templates need to be loaded into the homepage. If I don’t call for them then they won’t load. The code above is saying if it is a page template, include it.. else, include everything else. Your way would accomplish the same task but with a whole lot more code.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".