Jump to content

slaterino

Members
  • Posts

    128
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

slaterino's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. I am currently using a simple array with a grid layout that outputs from Wordpress, which allows me to specify the three columns of the grid. Now, I am wanting to add something hard-coded into the third column of the first row. Which essentially means that my array would need to go 'first,second' for the first row (then I will add my hard-coded item in the third column) and then 'first,second,third' infinitely after that. Is there any way that this is possible to implement practically, so that the array just goes 'first' and 'second' and then switches to the 'first','second,'third' array? Here's the current code that I'm using: $style_classes = array('first','second','third'); $styles_count = count($style_classes); $style_index = 0; <div class="grid_5 <?php $k = $style_index % $styles_count; echo "$style_classes[$k]"; $style_index++; ?>">
  2. Hi, I'm having a real problem with one of my Wordpress category pages. I use a 3-column grid system on this page and just recently I needed to add an advert to the page, so I thought I would do one query at the top with the first two posts, then add the advert to complete the row. Then I would use a second query underneath creating the posts using the traditional grid system with 3 in each row. This is working well except for the pagination, which adds the two items form the first query everytime it paginates. You can see this in action at http://soundsandcolours.com/music/ Does anyone know what I can do to make the Pagination ignore the first query, and just keep running the second query instead. I've included all of my code below: 1st Query: $query_string; $musiccat_posts = new WP_Query($query_string."&posts_per_page=2"); if ($musiccat_posts->have_posts()): $musiccatIDs = array(); while($musiccat_posts->have_posts()):$musiccat_posts->the_post(); $musiccatIDs[] = get_the_ID(); 2nd Query: $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; global $moremusiccat_query; $music_args = array( 'cat' => 1841, 'posts_per_page' => 15, 'post__not_in' => $musiccatIDs, 'paged' => $paged ); $moremusiccat_query = new WP_Query( $music_args ); while ($moremusiccat_query -> have_posts()) : $moremusiccat_query -> the_post(); ?> Pagination Code: $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $moremusiccat_query->max_num_pages ) ); Any help would be massively appreciated!
  3. Hey, that's what I thought too. However, none of the files listed actually ever existed, which is why I think there has been some hacking at some point that is causing the problem.
  4. Hi, Apologies if this isn't the right forum for this question. I couldn't find the perfect forum for my question, but I'm hoping someone can help. Basically, I've been having problems with a site I manage, with the site going down regularly, 401 Forbidden error pages cropping up reguarly, as well as Server Configuration Error pages, although only ever sporadically. I've been trying everything to work out the issue but no luck as of yet. However, one thing that seems strange is the following messages that I'm getting in the access logs. Now, this shouldn't be a problem as Facebook often creates messages like these when it's accessing files from a server. However, there are thousands of messages like this that reference files that don't exist. Honestly, it's constantly trying to access .jpg files that don't exist, and so I suspect this is what's causing the server to keep crashing. Has anyone had anything similar to this before? comono.co.uk 173.252.88.88 - - [20/Nov/2015:13:13:46 +0000] "GET /uploads/2009/9/28/873128bf77.jpg HTTP/1.1" 403 379 "-" "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)" Thanks, Russ
  5. Hi, I am currently building a site which works perfectly as it is. However, I am now trying to add mobile responsiveness and having trouble with what I think is the order in which the JavaScript files are loading. Essentially, I have a slideshow on the main page but I don't want this to load on mobile devices so am using Enquire.js to set some parameters. However, even though it looks like it's working in the code there are some problems. First off, in my script, I load the JavaScript files: <script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script> <script src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js" type="text/javascript" charset="utf-8"></script> Then I load the loadJS function and initialise the jQuery tool: <script type="text/javascript"> function loadJS(url) { var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; head.appendChild(script); }; (function($) { jQuery('#slides').slides({ preload: true, generateNextPrev: true }); }); </script> This all works fine. My problem is that I want jQuery Tools to only open if the computer is not a mobile. So, instead of loading the script in the header I have this script later on in the file: enquire.register("screen and (min-width: 900px)", { match : function() { loadJS('http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js'); console.log('desktop loaded'); } }); However, even though that script loads the JavaScript in the header the jQuery Tools are not initialising properly and the slideshow is not working. Why is this happening? Any help even with how I can debug this would be really appreciated. Thanks, Russ
  6. Hey all, sorry to come back onto this topic, but I have one final question. Essentially I need my data to be sorted by two different valuables, the date and the artist name. When I do a Foreach loop such as the one in the example above is there any way of sorting the $artist_name field alphabetically?
  7. And in case anyone wants to see the final code, here it is: $todaysDate = date('Y/m/d'); global $post; $args = array( 'post_type' => 'event', 'orderby' => 'meta_value', 'meta_key' => 'event_date', 'meta_compare' => '>', 'meta_value' => $todaysDate, 'numberposts' => 6, 'order' => 'ASC' ); $whatson = get_posts( $args ); $output_array = array(); foreach( $whatson as $post ) : if (get_post_meta($post->ID, '2artist', true)) : $artist_name = get_the_title(get_post_meta($post->ID, '2artist', true)); elseif (get_post_meta($post->ID, '2artist_non', true)) : $artist_name = get_post_meta($post->ID, '2artist_non', true); endif; $event_date = date('D j M', strtotime(get_post_meta($post->ID, 'event_date', true))); $output_array[$artist_name][] = $event_date; endforeach; foreach($output_array as $artists=>$events) : echo "<h1>$artists</h1>"; foreach($events as $event) : echo "<h2>$event</h2>"; endforeach; endforeach;
  8. Guys. I got it! Sorry, I forgot to take out the $output_array from within the loop! I think I can work from what I have now. It looks like it works a charm. Thanks for your help!
  9. Hmm, I just tried that Barand so that my code looks like the below, but my array only includes one entry, the last entry. Is there something I'm missing? $output_array = array(); foreach( $whatson as $post ) : if (get_post_meta($post->ID, '2artist', true)) : $artist_name = get_the_title(get_post_meta($post->ID, '2artist', true)); elseif (get_post_meta($post->ID, '2artist_non', true)) : $artist_name = get_post_meta($post->ID, '2artist_non', true); endif; $event_date = date('D j M', strtotime(get_post_meta($post->ID, 'event_date', true))); $output_array = array(); $output_array[$artist_name][] = $event_date; endforeach; print_r($output_array); And that's just outputting: Array ( [Artist Name #2] => Array ( [0] => Thu 20 Dec ) )
  10. And just to make clear, this is the output I'm getting: Array ( [Artist Name #1] => Array ( [0] => Tue 20 Nov ) ) Array ( [Artist Name #2] => Array ( [0] => Wed 28 Nov ) ) Array ( [Artist Name #2] => Array ( [0] => Thu 20 Dec )
  11. Hey, I've tried using this two-dimensional array but still getting the standard result, which is where the artist names are not grouped together. I've included the code below. I can't help but think that I would need to break out of the initial foreach loop to be able to do this. Do you know what I mean? Here's the code: $args = array( 'post_type' => 'event', 'orderby' => 'meta_value', 'meta_key' => 'event_date', 'meta_compare' => '>', 'meta_value' => $todaysDate, 'numberposts' => 6, 'order' => 'ASC' ); $whatson = get_posts( $args ); foreach( $whatson as $post ) : $artist_name = get_the_title(get_post_meta($post->ID, '2artist', true)); $event_date = date('D j M', strtotime(get_post_meta($post->ID, 'event_date', true))); $output_array = array(); $output_array[$artist_name][] = $event_date; foreach($output_array as $artists=>$events){ print_r($output_array); echo "<h1>$artists</h1>"; foreach($events as $event){ echo "<h2>$event</h2>"; } } endforeach;
  12. Okay, I've created an array now within the current foreach loop. How can I now echo this so that the outputted values are grouped by the artist name?? Here's the array: if (get_post_meta($post->ID, '2artist', true)) : $artist_name = get_the_title(get_post_meta($post->ID, '2artist', true)); elseif (get_post_meta($post->ID, '2artist_non', true)) : $artist_name = get_post_meta($post->ID, '2artist_non', true); endif; $event_date = date('D j M', strtotime(get_post_meta($post->ID, 'event_date', true))); $artists = array(); //define dates array. $artists[] = $artist_name; $artists[] = $event_date; print_r ($artists);
  13. Hi, I'm hoping this is something quite basic. I'm trying to group values from a MySQL query into an array. I have a Wordpress set-up but I'm presuming this is more of a PHP rather than a Wordpress concern. I just want to know basically what is the best way of doing this. Essentially I currently have the following data: Artist Name #1 - Event Date #1 Artist Name #2 - Event Date #2 Artist Name #1 - Event Date #3 Artist Name #1 - Event Date #4 And I want to find a way that I can group the Artist Names so that the data would output like this: Artist Name #1 Event Date #1 Event Date #3 Event Date #4 Artist Name #2 Event Date #2 This is the code I have at the moment. How would I integrate an array and an extra Foreach loop to get the data organised like this. I'm still learning Arrays at the moment and would appreciate any assistance with this. global $post; $args = array( 'post_type' => 'event', 'orderby' => 'meta_value', 'meta_key' => 'event_date', 'meta_compare' => '>', 'meta_value' => $todaysDate, 'numberposts' => 6, 'order' => 'ASC' ); $whatson = get_posts( $args ); foreach( $whatson as $post ) : echo get_the_title(get_post_meta($post->ID, '2artist', true)) . " - "; echo get_post_meta($whatson_query->ID, 'event_date', true); endforeach; Thanks! Russ
  14. Hey, Thanks for the advice. Literally, there will only be 1 or none results so my query is just to find out whether that one result exists or not. So, I think I will do it the way that fugix suggested. Cheers!
  15. Right, I have a table with two fields. One of these is $event_ID, the other is $object_ID. In php, I am running a while loop for all my $event_ID's taking data from another table. Now, in that while loop all I want to do is search through the table I just mentioned and find any matching $event_ID's. If the $object_ID = 7 I simply then want to echo a little bit of data. What's the best way of doing this? I was thinking that I should create an SQL query, i.e. "SELECT event_ID, object_ID FROM event_object_table WHERE event_ID = '$event_ID', and then running another WHILE loop with an IF clause saying something like: IF ($object_ID = 7) {echo "true";} Is this the best way to do this? Or is there a more efficient way? That's really what I'm after!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.