Forum Replies Created

Viewing 15 replies - 1 through 15 (of 19 total)
  • Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    Ok, so some more detail.

    My custom page below. what I want to do is put everything within the <body> tag into a plugin so I can include it as a shortcode on the page (and therefore the members plugin will act upon everything on the page).

    <?php
    /**
    
     */
    
    get_header(); ?>
    <?php while ( have_posts() ) : the_post(); ?>
    
    		<?php get_template_part( 'content', 'page' ); ?>
    
    		<?php
    			/**
    			 * rock_star_comment_section hook
    			 *
    			 * @hooked rock_star_get_comment_section - 10
    			 */
    			do_action( 'rock_star_comment_section' );
    		?>
    
    	<?php endwhile; // end of the loop. ?>
    
    <body>
    	
    	<h1>
    		This is the Gig Bible!
    </h1>
    	  <h3>Here's what we've got - keep checking back for updates - don't forget to add your unavailable dates.</h3>
    	<p>
    		...back to <a href="<?php echo(site_url()) ?>/admin">admin</a>
    	</p>
    <style type="text/css">
    
    td {
    
    }
    
    tbody {
    	background-color: black;
    }	
    
    a {position: relative;}
     
    a:hover span {
      position: absolute;
      top: 5px;
      left: 30px;
      display: block;
      background: #fdd;
      border: 1px solid red;
      }
    a:link{ text-decoration: none;
    	color: white;
    }
    	
    a:visited{ text-decoration: none;
    	color: white;
    }
    
    a:hover{ text-decoration: none;
    	color: white;
    	font-weight: bolder;
    	
    }
    .gig_day {
     font-weight: bolder;
     color: white;
     background-color: limegreen;
     text-align: center;
    text-decoration: none;	
    }
    .unav_day {
     font-weight: bolder;
     color: white;
     background-color: darkgrey;
     text-align: center;
    	
    }
    .otherevent_day {
     font-weight: bolder;
     color: white;
     background-color: blue;
     text-align: center;
    	
    }
    
    </style>
    
    <?php
    
    $mysqli = new mysqli("host","user","password","database");
    
    // Check connection
    if ($mysqli -> connect_errno) {
      echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
      exit();
    }
    
    //$link="#";
    
    $class="gig_day"; 
    
    # PHP Calendar (version 2.3), written by Keith Devens
    # http://keithdevens.com/software/php_calendar
    #  see example at http://keithdevens.com/weblog
    # License: http://keithdevens.com/software/license
    
    function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 1, $pn = array()){
    	$first_of_month = gmmktime(0,0,0,$month,1,$year);
    	#remember that mktime will automatically correct if invalid dates are entered
    	# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
    	# this provides a built in "rounding" feature to generate_calendar()
    
    	$day_names = array(); #generate all the day names according to the current locale
    	for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
    		$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name
    
    	list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
    	$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
    	$title   = htmlentities(ucfirst($month_name)).'&nbsp;'.$year;  #note that some locales don't capitalize month and day names
    
    	#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
    	@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
    	if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span>&nbsp;';
    	if($n) $n = '&nbsp;<span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
    	$calendar = '<table class="calendar">'."\n".
    		'<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";
    
    	if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
    		#if day_name_length is >3, the full name of the day will be printed
    		foreach($day_names as $d)
    			$calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    		$calendar .= "</tr>\n<tr>";
    	}
    
    	if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'">&nbsp;</td>'; #initial 'empty' days
    	for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    		if($weekday == 7){
    			$weekday   = 0; #start a new week
    			$calendar .= "</tr>\n<tr>";
    		}
    		if(isset($days[$day]) and is_array($days[$day])){
    			@list($link, $classes, $content) = $days[$day];
    			if(is_null($content))  $content  = $day;
    			$calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
    				($link ? '<a '.($link).'" href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
    		}
    		else $calendar .= "<td>$day</td>";
    	}
    	if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'">&nbsp;</td>'; #remaining "empty" days
    
    	return $calendar."</tr>\n</table>\n";
    }
    
    $time = time(); 
    $today = date('j',$time); 
    
    //echo generate_calendar(date('Y', $time), date('n', $time), $days, 3, '/guard_admin.php'); 
    ?>
    
    <div class="GigBibleMain"><table border=.5 ">
    <tr>
        <?php $time = time();
                   for($month=1; $month<=12; $month++){ ?>
            <td style="vertical-align: top";>
    		
                <?php
    //Gig bible query
    $sql = "
    select 
    SCGD_Desc,
    Day(SCGD_Date) as 'gig_date',
    case
    when SCGD_IsUnavailable = '1' then 'unav_day'
    when SCGD_IsOther = '1' then 'otherevent_day'
    else  'gig_day'
    end as 'gl_color'
    from SC_GigDates
    where month(SCGD_Date) = $month
    ";
    
    $result = $mysqli -> query($sql);
    $arr = array();
    $link = array();
    while($row = mysqli_fetch_array($result)){
       $arr[$row['gig_date']] = array('title="'.$row['SCGD_Desc'].'"',$row['gl_color']);
       
      
    }
    
    			//echo generate_calendar(date('Y', $time), $month, $arr);
    			echo generate_calendar(2022, $month, $arr);
    			?>
            </td>
            <?php if($month%3 == 0 and $month<12){ ?>
                </tr><tr>
            <?php } ?>
        <?php }
    unset($arr);
    $result -> free_result();
    
    //Event List
    $sql = "select * from SC_GigDates order by SCGD_Date";
    
    $result = $mysqli -> query($sql);
    
    //$row = $result -> fetch_array(MYSQLI_ASSOC);
    $arr = array();
    
    echo "<table border=.5px>";
    while ($row = mysqli_fetch_assoc($result)) {
    	echo "<tr><td>".$row['SCGD_Date']."</td><td>".$row['SCGD_Desc']."</td></tr>";
    }
    echo "</table>";
    
    $result -> free_result();
    
    $mysqli -> close()
    
    	?>
    </tr>
    </table></div>
    </body>
    <?php
    
    get_footer(); ?>
    
    

    Firstly – can I simply paste the whole lot into a plugin file and secondly, can I do it as an include?

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    Thanks for your reply.

    It’s more a conceptual question really – the code itself sits outside of the loop, therefore it isn’t effected by the Member plugin
    The Member plugin works fine.

    I can post more detail later when I’m at home, but basically my code sits below the WordPress loop so is there a way to get it as part of the WordPress content or should I put my code into a plugin and add it to the page with a short code?

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    Ah – that makes a lot of sense!

    I’ll change my field names to ‘Unavailable’, ‘Gig’ and ‘Rehearsal’.

    I tried with ‘==’ but it wasn’t returning anything – I’ll try again and see if I can spot something odd in what it’s looking up.

    I’m just really learning about CSS (beynd the basics), sounds like a much better idea to determine the class from the post type than using inline CSS.

    Thanks!

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    I managed to figure it out.

    It turns out that I must have entered my dummy posts before setting the date format to YYYY-MM-DD.
    After I tried editing and saving down each of the dates it worked fine!

    …agreed on the naming convention though, I’ll change that to avoid future problems.

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    @howdy_mcgee what I mean by excluding other types is…

    The band can enter three or four different types of event post (Advanced Custom Field – ‘Type’ field).
    So for instance any band member can enter a ‘Gig date’, an ‘Unavailable date’, a ‘Rehearsal date’ and an ‘Other date’ so we can create a calendar of events for our eyes only on a private page for logged in band members.

    On the front end I only want to show the ‘Gig date’ entries out of the same list.

    So, in all, its a custom post type of ‘Events’ filtered to only show ‘Gig date’ (ACF custom field) and ordered by ACF ‘Date’ field.

    I’ve done this before using pure HTML/CSS and MySQL tables but I’m trying to learn how to do this purely in WP so I can make use of functionality that’s already there.

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    👍

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    Hahaha!!!

    …and I’ve been staring at it for so long!

    Thanks!

    I’ll no doubt be back on shortly asking about a missing semi-colon 😀

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    Thanks for your reply.

    I’m going to try using Advanced Custom Fields to add fields to posts such as ‘Gig date’, location etc, and then try and build custom entry and update pages that user can use to manage posts.

    I guess this is a fairly common thing so hopefully there’s some helpful resources online to help out with this.

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    ….fixed it!

    it was the Gigpress plugin setting ‘Exclude this category from my normal post listings.’

    Forum: Your WordPress
    In reply to: My drumming site
    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    Thanks for the comment…….it’s kind of deliberate really, the idea is that the site is virtually black and white in order to highlight the colours in my photos – obviously there’s not much in there yet.

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    ….anyone else done something similar?

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    I thought that might be the case.

    Strangely enough, when I uploaded my plugin to my site (was running it localhost), the layout is fine……I must have some differences between my online/offline versions.

    Its seems fine across different browsers………I will give those resources a read through though as I know that some of the code is deprecated.

    thanks,

    Darren

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    That’s it!!!

    Brilliant!!

    Thanks for your help – I’ve just got a few CSS problems to sort out and I should be good!!

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    I think I’m getting closer to cracking this….

    Your suggestions make sense to me from the point of view of structuring (given that I don’t know very much about wordpress).

    But, fundamentally, by structuring the while loop like that, I can only get ‘$my_string’ to output the last record in the array.

    I’m testing this by running the giglist.php on its own, if I go back to having ‘echo’ in place of ‘$my_string =’ I get the whole array as output……if I switch to your method above (swapping ‘echo’ for ‘$my_string’ and then calling $my_string after the loop), $my_string only stores the last record.

    So, I guess the problem is getting the variable to store and output the array rather than one record……I think :-S

    PS…I realise that in the query above I have ‘limit 1,1’ in the ‘order by’….obviously, I’ve removed this and can verify that all rows are output when using ‘echo’ as described above.

    Thread Starter Dazzathedrummer

    (@dazzathedrummer)

    ok well I got a bit further.

    I got it to work (sort of) by setting the ‘while’ result as a variable and then calling it with ‘return’ after the include in the function like this…..

    function gig_bible_list() {
    include ('giglist.php');
    return $mygigs;
    }

    This puts the results in the correct position in the widget box, but only returns the last record in the array – if I can just get this to output the whole array, this would be perfect.

Viewing 15 replies - 1 through 15 (of 19 total)