How it works right now:
It shows the latest 6 projects as default
When pressing the specific lists it shows the latest post within that category that are the latest 6 projects. E.g: It shows the 4 latest within Foto because 4 of the 6 are categories as Foto. This mean that if the 6 latest projects are in the category Foto, none of the posts within the other categories would show. Please see screenshow below if you don't understand.
How it should work:
Show the latest 6 projects as default (this works)
When press one category it should show the latest 6 posts within that category
See page here
Note: If you are using Chrome with Windows 10 the hover effect has for some reason stopped working. The bug has been reported to Chrome and Windows
<ul id="filters" class="whitetext whitelink myeluft">
<li class="smoothtrans">Alle</li>
<li class="smoothtrans">Foto</li>
<li class="smoothtrans">Video</li>
<li class="smoothtrans">Web</li>
</ul>
PHP
<?php
$args = array(
'post_type' => (array( 'foto', 'video', 'web' )),
'posts_per_page' => '6',
'post_taxonomy' => 'any',
);
$the_query = new WP_Query($args);
// Loop post_type
?>
<?php if ( $the_query->have_posts() ) : ?>
<div id="isotope-list">
<?php while ( $the_query->have_posts() ) : $the_query->the_post();
$termsArray = get_the_terms( $post->ID, "category"); //Get the terms for this particular item
$termsString = ""; //initialize the string that will contain the terms
foreach ( $termsArray as $term ) { // for each term
$termsString .= $term->slug.' '; //create a string that has all the slugs
}
?>
<div class="<?php echo $termsString; ?> item col-md-4">
<ul class="grid cs-style-3">
<li>
<figure>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail('frontpage_thumb');
} ?>
<figcaption class="lefttext">
<h3><?php the_title(); ?></h3>
<span class="offgrey"><?php echo(types_render_field( "produkt", array( 'raw' => true) )); ?> / <?php echo(types_render_field( "produsert", array( 'raw' => true) )); ?></span>
Se prosjekt
</figcaption>
</figure>
</li>
</ul>
</div> <!-- end item -->
<?php endwhile; ?>
</div> <!-- end isotope-list -->
<script src="<?php bloginfo('stylesheet_directory'); ?>/js/toucheffects.js"></script>
<?php endif; ?>
JS
jQuery(function ($) {
var $container = $('#isotope-list'); //The ID for the list with all the blog posts
$container.isotope({ //Isotope options, 'item' matches the class in the PHP
itemSelector : '.item',
layoutMode : 'masonry'
});
//Add the class selected to the item that is clicked, and remove from the others
var $optionSets = $('#filters'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('#filters');
$optionSets.find('.selected').removeClass('selected');
$this.addClass('selected');
//When an item is clicked, sort the items.
var selector = $(this).attr('data-filter');
$container.isotope({ filter: selector });
return false;
});
});
My thoughs (updated 13/07/15)
I have looked more into it, and when disabling the 'posts_per_page' and just using the custom wp settings, the problem is the same. So I guess that the problem is that when pressing each category it does not refresh or get any other posts than first shown.
I therefore believe that the args must be set another place, or the js must be modified to get newest posts. But this is not my expertise, and therefore I ask you if you have any solution. I have searched on both search engines and SO for this question, but I couldn't find it. However, I see that similar pages have the same problem. With that I believe that solving this problem would help other users aswell.
Your current code ask to the database for 6 recent posts only. Isotope plugin then filter them on the frontend.
This means that it can't show more post apart from this 6. When you click on the tags (foto, video, web) isotope filter this 6 posts to show only the ones that have the selected category. It doesn't ask for any more posts, it only filter the posts you already have.
You can make your code ask for more posts when you click on the filter tags, but you will need to use AJAX.
Two Things I don't understand
Why their are two navigation/choice
2.First one work correct but second does not have any link or function it has link to just back to same using # hyper reference.
3.video and web have same thing did you put it knowingly if not check assigned category
one thing you can do is fetch all the posts at once and show only 6 using something like this
jQuery('#isotope-list').isotope({
filter: ':nth-child(-n+3)'
});
Filter will work only on available items on page.
When pressing one category it should show the latest 6 posts within that category if available, in your case (http://www.vekvemedia.no/) total item are 6 and 5 item belongs to "foto" category so when pressing "foto" category it will show 5 items.
Solution-1: if you have "All" option then you have to load all the available items in first load after that filter will work and show all the items of matching category.
Solution-2: By using ajax, fetch 6 records that match category(like "foto")
Related
Okay guys, this one has me somewhere between ripping my hair out and kicking in my monitor. It seems no matter what I try, no matter how many times I re-write the query, change terms, change syntax...I get nothing.
So I have a website I am working on where we have a custom post type of 'Vinyl' for vinyl records of in an online collection the client wants displayed alphabetically, with a category of 'vinyls' inside the custom post type section. The client then further wanted to separate things down and create a child category within 'vinyls' called 'vinyl_ae' (Vinyls alphabetically sorted by the first letter A through E). Now, I have the issue where I am trying to query any post at all from the vinyl_ae category/sub-category/whatever the hell it is at this point, and NOTHING turns out. The only way I get any results at all is to set an else conditional for the if have_posts() statement. I'll try to include any all data I can here to help sort this mess out.
Custom post type - name : vinyl
main category - name : VINYLs, slug : vinyls, ID : 3
child category - name : Vinyl A-E, slug : vinyl_ae, ID : 4571
Screen Shots of all my category and sub-category layouts
Here is my working Code Currently (take in mind I have stripped it down so much tonight there is not much left and I have tried so many different solutions to the point where I am practically copying and pasting based on results others are having)
<section id="main">
<div class="content-holder no-spacing">
<div class="container">
<div class="content-inner">
<div id="ajax" class="records row">
<?php
$args = array(
'post_type' => 'post' ,
'posts_per_page' => 6,
'cat' => '4571',
'paged' => get_query_var('paged'),
'post_parent' => $parent);
$mv = new WP_Query($args);
if ( $mv->have_posts() ) {
while ( $q->have_posts() ) {
$serial = get_field('serial');
$mv->the_post(); ?>
<div class="serial-num"><?php echo $serial; ?></div>
<?php } ?>
<?php } else { ?>
<em>Things Still Screwy</em>
<?php } ?>
</div>
</div>
</div>
Thank any and all in advance for any help that can be given, I've thrown in the towel here.
There is two things that you should consider in your sample code:
You should set post_type argument to your custom post type vinyl not the post post type.
If the serial is a field of your post you should call the $mv->the_post(); line first and after that call the $serial = get_field('serial'); statement, because before the_post() call, you can't access post's meta data.
This question already has answers here:
How can I apply a jQuery function to all elements with the same ID?
(4 answers)
Closed 5 years ago.
I have a wordpress site where my index page will display the post title, thumbnail, and list all available post categories. Each instance of a post will also display all available post categories. For each category the post has, the category name should be highlighted with a light blue background color. Currently the background color feature is working for only the first post and not the other three.
My code below is intended to push each of the post's categories into an array and search the array for the given category (the code below searches for just one of the categories for brevity's sake here). If the category is found, a jQuery script should execute highlighting the category name but as I say above, it's only functioning for the first post.
Can anyone see what I'm doing wrong? Thanks in advance.
<section class="blog-index">
<?php
$args = array('showposts' => 3);
$recent = new WP_Query( $args );
if( $recent->have_posts() ):
echo '<div class="blog-index-list">';
while ( $recent->have_posts()) :
$recent->the_post();
$categories = get_the_category();
$cats = array();
foreach($categories as $category) {
$cats[] = $category->name;
}
if(in_array("Academia", $cats)) {
echo "<script type='text/javascript'>
jQuery('#A').addClass('active');
jQuery('#A').css({'background-color': #009edb', 'color': '#ffffff'});
</script>";
}
echo '<article>
<h2><hr class="orange-line above-left"> <a href="'.get_the_permalink().'">
<span class="dark-blue">' .get_field('dark_blue_hero'). '</span><br/>
<span class="light-blue">' .get_field('light_blue_hero') . '</span></a>
</h2>
<ul class="all-categories">
<li id="G">G</li>
<li id="A">A</li>
<li id="I">I</li>
<li id="N">N</li>
</ul>
<img src="'.get_the_post_thumbnail().'' .
'<div class="blog-index-button et_pb_button_module_wrapper et_pb_module et_pb_button_alignment_center">
<a class="et_pb_button et_pb_button_3 et_pb_module et_pb_bg_layout_light" href="' . get_the_permalink() . '">READ POST</a>
</div>
</article>';
endwhile;
echo '</div>';
endif;
wp_reset_query();
?>
IDs should be unique (as Barmar said) but it is still possible to have multiple elements with the same ID. And it is possible to select them with jQuery. That is why I'll also explain how to do it with classes.
When you use the jQuery ID selector (jQuery("#id")) it selects the first element with the given ID id.
To select all elements with ID id you can select them by their attribute(s):
jQuery("li[id=id]")
Since IDs should be unique it is better to use classes. Using the jQuery class selector jQuery(".class") you can select all the elements with the class class. You should change your li elements to have classes instead of IDs and select those classes with jQuery.
I have installed Widget Logic on a Wordpress site. Using is_single('this') it correctly displays the widget on the page. But, I need
'this' to be a variable and match another variable.
What I'm looking for is the PHP equivalent of a SQL "where" clause that will match one field to another. Select x from y where a=b;
I have posts that represent a "Location" - could be London, Paris, Munich.
I have posts that represent "Services" and can be filtered by location.
I have a widget that displays available services.
I want to dynamically filter what is displayed by the widget according to the location. If I have a Munich post, only those services available in Munich are displayed in the widget and only those services available in London are displayed on the London page.
I've tried setting Widget Logic to about 20 variations of 'field1'=='field2' or
$field1==$field2 and is_??(??) / in_??(??) No joy.
Maybe I have the syntax wrong? or using the wrong WP conditional tag?
Using Widget Logic for this didn't work out. The following runs in a PHP Text box widget on the WordPress page
$fish is the title of the post being displayed (e.g., London)
The related posts all have a 'meta-value' that includes the location (e.g., London)
<?php
$fish = get_queried_object_id();
if ('$fish' != null ) {
query_posts (array ('post_type' => array('accommodation'), 'meta_value' => $fish,
'orderby' => 'asc', 'showposts' => 3) );
if (have_posts()) : while (have_posts()) : the_post();?>
<h4><a href="<?php the_permalink() ?>">
<?php the_post_thumbnail( 'thumbnail'); ?>
<?php the_title(); ?></a></h4>
<?php endwhile;
endif;
} else {
echo "why is this here?";
}
?>
Working on a site, and I need to have a separated template/page for showing just that one post.
On the home page (index) Ill loop through my categories and showing just a part of them - events - news - references.
Like this:
<?php
$query = new WP_Query( array( 'category_name' => 'Events' ) );
if ($query->have_posts())
{
while ($query->have_posts()) : $query->the_post();
$haveEvents = true;
if ($eventCount < 3) {
$eventCount++;
?>
<div class="event-tile">
<div class="event-tile-content">
<h3><?php the_title(); ?></h3>
<h4><?php the_time('F jS, Y'); ?></h4>
Lees meer
</div>
</div>
<?php
}
endwhile;
}
Every section has a read all and read specific item button:
I already found out how to display all posts within a category on a separated page named: page-posts.php
On page-posts.php I simply check on which page I am and depending on which page, make a query to show the posts within a specified category
$query;
if (is_page('events')) {
$query = new WP_Query( array( 'category_name' => 'Events' ) );
}
elseif (is_page('news')) {
$query = new WP_Query( array( 'category_name' => 'News' ) );
}
if ($query->have_posts())
{
etc..
Now what I cant figure out (not even after spending like hours on google), how to show a single post from the home page (index.php), on a single-post page...
On the action buttons I use:
Lees meer
Which brings me back to the homescreen. (just started on Wordpress)
In a Wordpress theme single.php is used to display a post. If it does not exist it drops down to using your index.php
Try moving your page-posts.php to single.php
Maybe its better to use archive-events.php. You can make an archive for custom posts.
With that you can do: where events is your custom post-type. Then you land on the events archive page.
As far as i can see your problem is that the post is the global post (from your home). So maybe you can setup_postdata($post), or use the home_url('url') functions.
I've used wordpress Advanced Custom Fields plugin to make my portfolio page. I've setup fields for the image, title, category and a yes/no for weather the project is featured.
My code for the project page is as follows:
<?php
$args = array(
'post_type' => 'project'
);
$query = new WP_Query( $args );
?>
<?php Starkers_Utilities::get_template_parts( array( 'parts/shared/html-header', 'parts/shared/header' ) ); ?>
<h1 class="lead"><?php the_title(); ?></h1>
<div id="triggers">
<strong>Filter:</strong>
<span id="filterDouble">Filter All</span>
<span id="filter1">Filter 1</span>
<span id="filter2">Filter 2</span>
</div>
<ul id="gallery" class="group">
<?php if ( have_posts() ) while ( $query->have_posts() ) : $query->the_post(); ?>
<li class="gallery_image" data-id="id-" data-type="<?php the_field('project_category')?>">
<a rel="prettyPhoto[gallery]" class="zoom" href="<?php echo the_field('image') ?>">
<img class="mag" src="<?php bloginfo('template_url'); ?>/imgs/mag.png"/><div class="thumb_bg"></div>
<?php the_post_thumbnail('portfolio'); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
Everything works fine, i can add projects. However My problem starts when i hit 10 projects. After 10, it doesn't display anymore. I am using jpages (jquery plugin) and filtrify to add filters to filer out the categories. They work fine, i can filter by category and i see the correct images. Even with the plugin scripts removed, i still only see a max of 10 posts. Adding more than 10 simply pushes the earlier images off and it displays the 10 latest.
So how can i stop it from being just 10.. My jpage script sets the pagination to 12 per page, but this doesn't even get a chance to kick in. I am thinking it's a post problem as I'm certain it's not the scripts.
I think I've traced an issue - I tested this: 'posts_per_page' => '20' - Which DOES display my missing posts, however i don't want to set a number as i might need lots. How can i define an unlimited number. Providing this is the issue..
If any other code is needed, please let me know, but i think this is the main part of what's controlling my posts appearing on the page.
You're on the right track.Set the value to -1 to get your desired results.
Link to the documentation: http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters
posts_per_page (int) - number of post to show per page (available with Version 2.1, replaced showposts parameter). Use 'posts_per_page'=>-1 to show all posts. Set the 'paged' parameter if pagination is off after using this parameter.