Difference between revisions of "Week Thirteen (MGDP2060)"

From Wiki @ Karl Jones dot com
Jump to: navigation, search
(WordPress custom theme examples)
(header.php)
Line 82: Line 82:
  
 
<pre>
 
<pre>
<?php
+
 
 +
<nav class="navbar navbar-default" role="navigation">
 +
  <div class="container-fluid">
 +
    <!-- Brand and toggle get grouped for better mobile display -->
 +
    <div class="navbar-header">
 +
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
 +
        <span class="sr-only">Toggle navigation</span>
 +
        <span class="icon-bar"></span>
 +
        <span class="icon-bar"></span>
 +
        <span class="icon-bar"></span>
 +
      </button>
 +
      <a class="navbar-brand" href="<?php echo home_url(); ?>">
 +
                <?php bloginfo('name'); ?>
 +
            </a>
 +
    </div>
 +
 
 +
        <?php
 
             wp_nav_menu( array(
 
             wp_nav_menu( array(
 
                 'menu'              => 'primary',
 
                 'menu'              => 'primary',
Line 95: Line 111:
 
             );
 
             );
 
         ?>
 
         ?>
 +
    </div>
 +
</nav>
 +
 
</pre>
 
</pre>
  

Revision as of 13:40, 3 December 2015

This article lists topics for Week Thirteen of Web Design and Development III (MGDP2060).

Previous class session

Next class sessions

  • Week Fourteen - lecture and lab time, but no exercise, no requirements
  • Week Fifteen - guest lecture(s), and (entirely optional) student presentations

WordPress: the loop

WordPress has a concept known as the the loop.

It is so named because it "loops around and around" some data.

Recordset and records

Typically the loop is processing a recordset, which consists of zero or more records.

A record is a unit of data, for example a blog post.

A record typically has multiple data fields. For example, a blog post record typically has fields for Title, Date Posted, Author, Content, etc.

Looping through a recordset

Use the loop to process a recordset, one record at a time.

1. Start at top of loop 2. Display any HTML, and run any PHP code, inside the loop. 2.1 Data in the loop pertains to one recordset at a time, in sequence: first record, second record, etc. 3. At the bottom of the loop, "loop back" to (1) until all records are processed.

You must stop the loop at some point. If you don't stop the loop, you have an "endless loop", which is a Bad Thing.

Stopping the loop

Stopping the loop involves boolean logic (true or false).

The logic can take several different forms. A typical example tests for data at the top of the loop:

  • Is there a record to process?
    • If true, continue with HTML and PHP inside the loop
    • False, jump to the next line of code after the loop

Links to online resources

wp-bootstrap-navwalker

wp-bootstrap-navwalker is "a custom WordPress nav walker class to fully implement the Bootstrap 3.0+ navigation style in a custom theme using the WordPress built in menu manager."

Download

functions.php

Place wp_bootstrap_navwalker.php in your WordPress theme folder /wp-content/your-theme/

Open your WordPress themes functions.php file /wp-content/your-theme/functions.php and add the following code:

// Register Custom Navigation Walker

require_once('wp_bootstrap_navwalker.php');

Also in the functions file:

register_nav_menus( array(
    'primary' => __( 'Primary Menu', 'THEMENAME' ),
) );

header.php

Update header.php to use the walker by adding code like this:


<nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="<?php echo home_url(); ?>">
                <?php bloginfo('name'); ?>
            </a>
    </div>

        <?php
            wp_nav_menu( array(
                'menu'              => 'primary',
                'theme_location'    => 'primary',
                'depth'             => 2,
                'container'         => 'div',
                'container_class'   => 'collapse navbar-collapse',
        'container_id'      => 'bs-example-navbar-collapse-1',
                'menu_class'        => 'nav navbar-nav',
                'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
                'walker'            => new wp_bootstrap_navwalker())
            );
        ?>
    </div>
</nav>

WordPress custom theme examples

See WordPress custom theme examples.

Next week

Next week -- Week Fourteen -- is the second-to-last class session.

There will be no exercise, no requirements.

That is, the lecture is informational: there will be no test or exercise which requires you to know this information.

we will discuss domain names, domain name registration, managing domain names, and related topics.

See Week Fourteen.

See also