WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Restaurant's Daily special (8 posts)

  1. r1987
    Member
    Posted 4 years ago #

    Hello.

    I'm building a website for a café/restaurant. That place has a daily special every day for 5 days a week. So actually what I'd thought it just could be a featured post plugin, but i haven't found a plugin that shows specific pages on a specific day of week in a div.

    Example:
    Monday -> show page_id=1
    Tuesday -> show page_id=2
    Wednesday -> show page_id=3
    Thursday -> show page_id=4
    Friday -> show page_id=5

    On Saturday and Sunday it should be empty, or show a picture or whatever.

    Can anyone help with this?

  2. keesiemeijer
    moderator
    Posted 4 years ago #

    Try this
    Put this before the loop:

    <?php
    $mydate = date("l");
    if($mydate == 'Monday') { $pageid= 1;}
    if($mydate == 'Tuesday') { $pageid= 2;}
    if($mydate == 'Wednesday') { $pageid= 3;}
    // etc etc
    
    query_posts('page_id='.$pageid);
    ?>
  3. r1987
    Member
    Posted 4 years ago #

    Thanks!

    It seems to work actually, but after that I have small problems with the layout.

    I have 4 divs on the front page: NEWS, DAILY SPECIAL, CONTENT, LINKS.

    After putting the php code to DAILY SPECIAL div it opens the queried page in the content div, not in the daily special. And when clicking on the links the content won't change.

    What seems to be the problem?

  4. keesiemeijer
    moderator
    Posted 4 years ago #

    Please provide a link to the page in question. without it there's not much anyone can do to help.

  5. alchymyth
    Forum Moderator
    Posted 4 years ago #

    What seems to be the problem?

    it might need a wp_reset_query(); at the end of the DAILY SPECIAL area, to reset the query string to 'normal' after the custom query.

  6. r1987
    Member
    Posted 4 years ago #

    Sorry, can't show it online yet, because I don't have the host for this page yet.

    Anyhow, I can paste the code here as well:

    I have the index.php, with 4 divs:

    <?php get_header(); ?>
    
    <!-- GATHERING DIV END -->
    <div class="grid_3" id="gathering">
    <h2>Gathering</h2>
    <br/>
      …
    </div>
    <!-- GATHERING DIV END -->
    
    <!-- DAILY SPECIAL DIV START -->
    <div class="grid_3" id="dailyspecial">
    <?php
    $mydate = date("l");
    if($mydate == 'Monday') { $pageid= 6;}
    if($mydate == 'Tuesday') { $pageid= 2;}
    if($mydate == 'Wednesday') { $pageid= 39;}
    
    query_posts('page_id='.$pageid);
    ?>
    </div>
    <!-- DAILY SPECIAL DIV END -->
    
    <!-- CONTENT DIV START -->
    <div class="grid_4" id="content">
     <?php if (have_posts()) : ?>
      <?php while (have_posts()) : the_post(); ?>
    
      <div class="post" id="post-<?php the_ID(); ?>">
        <h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
          <?php the_title(); ?>
          </a></h2>
    
        <div class="entry">
          <?php the_content('',TRUE,''); ?>
        </div>
      </div>
      <?php endwhile; ?>
      <div class="navigation">
        <div class="alignleft">
          <?php next_posts_link('« Older posts') ?>
        </div>
        <div class="alignright">
          <?php previous_posts_link('Newer posts »') ?>
        </div>
      </div>
      <?php else : ?>
      <h2 class="center">No posts found.</h2>
      <?php endif; ?>
    </div>
    </div>
    <!-- CONTENT DIV END -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    + sidebar.php where i have the nav.

    I'd like to show the Daily Special and the content on the front page, but it seems to me that the query_posts(); has somekind of a conflict, because the called out page in Daily Special appears in the content div, not where I'd like to see it (dailyspecial div). + the navbar gets paralyzed.

    To alchymyth:
    wp_reset_query(); helped that much that the dailyspecial didn't appear in the content div, but didn't appear in dailyspecial to.

    So.. any ideas ?

  7. r1987
    Member
    Posted 4 years ago #

    Alright!

    Think that got it to work.

    Here's the code, that goes to the DAILY SPECIAL div:

    <?php
    $mydate = date("l");
    if($mydate == 'Monday') { $pageid= 6;}
    if($mydate == 'Tuesday') { $pageid= /*page_id*/;}
    if($mydate == 'Wednesday') { $pageid= /*page_id*/;}
    if($mydate == 'Thursday') { $pageid= /*page_id*/;}
    if($mydate == 'Friday') { $pageid= /*page_id*/;}
    if($mydate == 'Saturday') { $pageid= /*page_id*/;}
    if($mydate == 'Sunday') { $pageid= /*page_id*/;}
    ?>
    <?php
        $featured = new WP_Query();
        $featured->query('page_id='.$pageid);
    ?>
    <?php while ($featured->have_posts()) : $featured->the_post(); ?>
    <?php the_content(); ?>
    
    <?php endwhile; ?>
  8. alpha_llama
    Member
    Posted 3 years ago #

    I'm building a 'daily special' plugin for exactly this purpose. Should be ready soon. I'll post back with a link once I do.

    !cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.