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.
Related
The problem: I have a site (under development) where I have generated a custom post type called "Products" . Inside I have different categories and posts. I would like to generate a menu like behaviour to my sidebar, but using google I haven't really stumbled onto something good. Who knows, maybe my idea is all wrong and is doable using some other solution.
Currently I have used WP Query to echo out all posts under one category. So this means that I have to manually copy code to echo new category with its posts when it is created. One solution is to create a menu manually, but i'd like to keep it auto-generated because users are not keen to do extra work and ofter forgot how it is done.
So, the question: Is my solution all wrong? How can i achieve menu like behaviour with class active for clicked category and its sub item? Is it better to just use pages?
Example of my code:
<?php
$args = array(
'post_type' => 'products',
'posts_per_page' => -1,
'cat' => 1
);
$query = new WP_Query( $args );
if ($query->have_posts()) {
echo '<ul>';
while ( $query->have_posts() ) : $query->the_post(); ?>
<li>Category name, title</li>
<li class="cpt-menu-item" id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
</li>
<?php endwhile;
echo '</ul>';
}
wp_reset_postdata();
?>
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?";
}
?>
I currently have a custom post type of Episode with a taxonomy of podcast. When i run the following loop on my archive page i am seeing that I have 149 posts
<?php
$args2 = array(
'posts_per_page' => 1000,
'post_type' => 'episode',
'podcast' => 'my-episodes',
'post_status' => 'publish'
);
$posts = get_posts($args2);
$count = count($posts);
echo $count;
?>
However, when I'm running this variation of the loop on my archive.php file (copied from the wordpress.org page), i am only getting 130 posts
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<small><?php the_time('F jS, Y'); ?> by <?php the_author_posts_link(); ?></small>
<div class="entry">
<?php the_content(); ?>
</div>
<p class="postmetadata"><?php _e( 'Posted in' ); ?> <?php the_category( ', ' ); ?></p>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
The loop is saying that my most recent entry was from the 5th, however i have been creating posts on a regular basis over the last few days. Are there any tests I can run to see why the most recent posts are not showing up on the archive page?
Your code appears to be correct. Double check that the posts that are missing are published and not set as a draft/saved. Also check that your custom taxonomy and post types are correct for the query you are running.
After reviewing the dashboard of the site per the recommendation of Tom here is what I was able to find
The site has a plugin called WPML activated. This allows the site to create content in multiple languages.
When the plugin is initially activated, it will ask for the site's native language and apply that to the existing posts and custom posts. This way if you were on an englsih version of the site you would see content ABC while on a spanish version you would see content XYZ.
There is a separate section inside of a custom post that allows you to make said custom post translatable. If this is not checked then your custom post will not display on any version of the site. The reason being (at least in my 5 minutes of research) is that because there is no language specified, it will not load on the language specific versions of the site
I have done two things to fix this:
I have added the ability to make the custom post translatable,
There is a setting that will allow you to display all content that is not translated on any version of the site as opposed to not displaying any content
Thank you everyone for your help.
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")
Ladies & Gentlemen, boys & Girls, Guru's, Geeks and Geniuses of all ages.
I am having a problem on my wordpress theme.
I am creating a website for a company which has an online shop. The hierarchy of the shop pages is as follows:
Shop
-Catagory Page
--Product Page
One of the category pages is called "Designs" which has a page ID of 22. What I would like to do in the sidebar <aside> of wordpress is display, as a link, the title and an image from the newest sub-page of the 'design' page. Each product page has an image defined using a custom field called "Product_Image".
I have found this code on stackoverflow which I've modified to display the data I need, but instead of just calling the latest sub-page of the design page it calls the latest page from the whole site.
<?php
$args=array(
'showposts'=>1,
'post_type' => 'page',
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?>
<?php echo "<img src='" . get_post_meta($post->ID, "Product_Image", true) . "' />"; ?>
</a>
</div>
<?php
endwhile;
}
?>
I am completely new to PHP. I have only just started learning using "Tutsplus - PHP Essentials".
Could anyone help me modify this code so it only displays the information from the latest sub-page of the Design Page.
You can add a new argument to your query to only get pages that are a subpage of the design page. So, modify your $args array to look like this:
$args=array(
'showposts'=>1,
'post_type' => 'page',
'caller_get_posts'=>1,
'post_parent' => '22' // get pages that are children of the design page
);
Leave the rest of your code as is, and it should work.
For future reference, see here for all of the WP_Query parameters: http://codex.wordpress.org/Function_Reference/WP_Query#Parameters