Community Forums › Forums › Archived Forums › Design Tips and Tricks › List of Post Titles in Category View
Tagged: category archive, posts_per_page, pre_get_posts
- This topic has 11 replies, 3 voices, and was last updated 8 years, 1 month ago by stevenrmoody.
-
AuthorPosts
-
September 9, 2016 at 11:42 am #192904stevenrmoodyParticipant
I'm using a minimal Child Theme with the framework for both my own site (Snake vs Crane) and a site at UC Berkeley which is for documentation.
I find that the "out of the box" category and search results is hard to read for users.
I've found instructions on how to filter out various elements of the post (content, metadata) but these approaches all result in (at least) each title in a separate box.
What I want is one box with all the titles of the results as a link, styled to they are not huge h1 headlines.
An article HERE: http://www.tilcode.com/wordpress-genesis-framework-showing-a-list-of-post-titles-in-category-view/ shares some code which ALMOST gives me what I want.
I tried the code on both of my sites.
On my martial arts site, the loop seems to have stopped after delivering only three or four titles. I could display a category that had 60 titles but only four would appear (all styles right because I styled the .category-post-title-list and added the container color and resized the font, etc).
On the documentation site for UCB, it stopped after one entry (that site is on Pantheon FYI). You can see that here by clicking on the categories on the sidebar: Asktico
This result is SO tantalizing, because if it would deliver ALL the results for the category, then it would be exactly what I want.
My other question is -- how can I do the SAME THING, but with the search results?
For documentation, users want to be able to quickly see the titles of the results, as "all at once" as possible. So one box, with a list of clickable titles would be perfect. So this code is so close to what I need! I just need a little help to take one more step in the right direction!
I would greatly appreciate any help!
Steve
http://dev-wpasktico.pantheon.berkeley.edu/September 9, 2016 at 11:46 am #192905Brad DaltonParticipantRemove the loop and add a new WP_Query to a archive.php file or any file which uses the WordPress Template Hierarchy.
September 9, 2016 at 11:53 am #192906sgoergerMemberAt first glance the code you linked seems just like what you would want, and the nature of the error you describe (not right # of posts) is just weird. I can't think of what would interfere for you...
If I were working on this I would get that code in there, and then take a look at error logs, dev tools console, inspect the source code, etc, to try and diagnose why this isn't working as expected...
September 9, 2016 at 12:28 pm #192910Brad DaltonParticipantBased on your code, the WordPress Reading settings control posts per page on archives however you can override using the following:
$query->set( 'posts_per_page', '-1' );
In a pre_get_posts function which is what you linked to.
September 9, 2016 at 12:58 pm #192911stevenrmoodyParticipantThank you!
I reset my Reading Settings to 100 and I got the results I wanted!
Of course, now the search results are lengthy strings of separate boxes.
Next step, figure out how to get the same results I'm getting from categories in my search results!
thanks again!
September 9, 2016 at 1:24 pm #192912Brad DaltonParticipantModify this line in the code
if( $query->is_main_query() && $query->is_category() || $query->is_search() ) {
September 9, 2016 at 2:34 pm #192915stevenrmoodyParticipantIn the code of search.php (in my Child Theme)?
thanks!
Steve
September 9, 2016 at 2:38 pm #192917stevenrmoodyParticipantCurrently search.php has this in it:
<?php
add_action( 'genesis_before_loop', 'genesis_do_search_title' );
function genesis_do_search_title() {
$title = sprintf( '<div class="archive-description"><h1 class="archive-title">%s %s</h1></div>', apply_filters( 'genesis_search_title_text', __( 'Search Results for:', 'genesis' ) ), get_search_query() );
echo apply_filters( 'genesis_search_title_output', $title ) . "\n";
}genesis();
[\php]
September 9, 2016 at 2:44 pm #192918Brad DaltonParticipantIn the code you linked to now becomes this:
September 9, 2016 at 2:46 pm #192919stevenrmoodyParticipantOh - I fixed that with your suggestion to modify my Reading Settings -- I upped the number (from 1) to 100 and I got the results I was looking for.
Thanks again.
September 9, 2016 at 2:52 pm #192920Brad DaltonParticipantThis code modification relates to your search page https://gist.github.com/braddalton/5a699631b860b7d8f45901c48b9a2335
Your 2nd Question:
Of course, now the search results are lengthy strings of separate boxes.Next step, figure out how to get the same results I'm getting from categories in my search results!
September 9, 2016 at 3:07 pm #192922stevenrmoodyParticipantSorry - I think I am not communicating well!
What I am looking for is to do a search using the search widget in the upper-right of the header and get results like what I am now getting in the results from "All Content" and (now) all of my links to the various categories -- that is, a list of post links all in one box.
Thanks for your assistance and sorry if I am not being clear.
Steve
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.