ericr23
Forum Replies Created
-
Forum: Alpha/Beta/RC
In reply to: Turn off “Post Revision”-featureWhy post revisions can be problematic: I sometimes revise posts on our site (center a photo, correct a typo). Today, I added a graphic to a post. Upon saving it, the change was no longer there in the editing pane, and on viewing it, the post was not found. Obviously some glitch in the database occurred, so I went into MySQL Admin to fix the post. But there was revision after revision. It will take me a while to figure out what needs to be done in there. What a mess, just to accommodate a rarely used niche feature. It’s a rare blog that has to be run like Wikipedia.
Adding complexity (while arguing for simplicity in not offering an option to disable it) that is not needed by almost all users is just asking for trouble. And the “space is cheap” argument sounds like an attempt to rationalize lazy programming — and the WordPress programmers certainly are not guilty of that.
Forum: Plugins
In reply to: add_feed not workingWorks in 2.6.
Forum: Fixing WordPress
In reply to: how to page custom database query (to sort by custom field)?Sorry, I haven’t checked in for a while.
The bottom-of-page navigation I used is posted above, but one might miss the later note that $numpages needs to be renamed. So here is the final:
<?php $precpage=$paged-1; $nextpage=$paged+1; if ($paged>1) { if ($precpage==1) { echo ('<a href="../../">« Home</a>'); } else { echo ('<a href="../' . $precpage . '/">« Preceding Page</a> • <a href="../../">Home</a>'); } } if ($nextpage<=$numofpages) { if ($paged==1) { echo ('<a href="./page/'); } else { echo (' • <a href="../'); } echo ($nextpage . '/">Next Page »</a>'); } ?>
And here is a different navigation scheme for the top of the page:
<?php echo ('<b>[</b> ' . $numposts . ' documents • <i>pages: </i> '); $i=1; while ($i<=$numofpages) { if ($i==$paged) { echo (' <b>' . $i . '</b>'); } else { if ($i==1) { echo (' <a href="../../">' . $i . '</a>'); } else { if ($paged==1) { echo (' <a href="./page/' . $i . '/">' . $i . '</a>'); } else { echo (' <a href="../' . $i . '/">' . $i . '</a>'); } } } $i++; } echo (' <b>]</b>'); ?>
Again, see them at work at https://www.wind-watch.org/documents/authors/
Forum: Plugins
In reply to: add_feed not workingIt is the same in WordPress 2.3.3.
Forum: Fixing WordPress
In reply to: how to page custom database query (to sort by custom field)?What code other than what is posted above (remembering to change $numposts to $numofposts or, better, to $xx_numposts) do you want to see?
Forum: Plugins
In reply to: Search in current categoryA shortcoming is that after you do the search, the page is no longer a category, but a search page — so a revised search in the category means going back to the category page to get the category form.
So here is another version, that parses the request string so the category search form will appear with the category search results page as well.
<?php if (is_search() || is_category()) { $nwpath = 'https://www.domain.org' . $_SERVER['REQUEST_URI']; $querylen = strlen($_SERVER['QUERY_STRING']); if ($querylen) { $nwpath = substr($nwpath,0,-($querylen+1)); } $nwcat = strpos($nwpath,'category'); if ($nwcat) { $catslash = strrpos($nwpath,'/',-2); $catlen = (strlen($nwpath) - $catslash) - 2; $nwcatslug = substr($nwpath,$catslash+1,$catlen); $searchcat = substr($nwpath,0,$nwcat+9) . $nwcatslug . '/'; ?> <form method="get" id="searchform" action="<?php echo $searchcat; ?>"> <input type="text" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s"> <input type="submit" id="searchsubmit" value="Search <?php single_cat_title(); ?>"> </form> <?php } } ?>
I’m sure there’s a better way to do this, but this works …
Forum: Plugins
In reply to: I need search in One custom CategoryThe search function is called with the “?s=” query. So maybe simply modifying the form will do what you want (I mean it works, I just don’t know if it’s what you’re after looking for):
<form method="get" id="searchform" action="https://www.domain.com/category/myspecialcat/"> <input type="text" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id=s> <input type="submit" id="searchsubmit" value="Search My Special Cat"> </form>
Forum: Fixing WordPress
In reply to: how to page custom database query (to sort by custom field)?Good advice!
Forum: Fixing WordPress
In reply to: how to page custom database query (to sort by custom field)?It turns out that $numpages is a WordPress-defined variable. I renamed my variable to $numofpages and it all works as expected.
Forum: Fixing WordPress
In reply to: how to page custom database query (to sort by custom field)?OK — here’s the new code in the custom Page template:
<?php $numpostss = $wpdb->get_results("SELECT COUNT(*) FROM $wpdb->postmeta wpostmeta, $wpdb->posts wposts WHERE wpostmeta.meta_key = 'Author' AND wposts.ID = wpostmeta.post_id AND wposts.post_status = 'publish'", ARRAY_N); $numposts = $numpostss[0][0]; $postsperpage = 30; $numpages = intval($numposts/$postsperpage); if ($numposts%$postsperpage) { $numpages=$numpages+1; }; $lastpageposts = $numposts-(($numpages-1)*$postsperpage); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ... navigation stuff ... $offset = ($paged-1) * $postsperpage; if ($paged==$numpages) { $postsperpage=$lastpageposts; } $posts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'Author' AND wposts.post_status = 'publish' ORDER BY wpostmeta.meta_value ASC LIMIT $offset, $postsperpage", OBJECT); foreach ($posts as $post) : setup_postdata($post); ?> ... loop stuff ... endforeach; ?> ... navigation stuff ...
I still have to recreate $numpages (but not any of the other variables) for that second navigation section.
Thanks again for the help.
Forum: Fixing WordPress
In reply to: how to page custom database query (to sort by custom field)?Never mind: It needed to go one down one more level:
$numposts = $numpostss[0][0];
Forum: Fixing WordPress
In reply to: how to page custom database query (to sort by custom field)?I’m having trouble getting the result of this query via the $wpdb query:
SELECT COUNT(*) FROM wp_postmeta, wp_posts WHERE wp_postmeta.meta_key = 'Author' AND wp_posts.ID = wp_postmeta.post_id AND wp_posts.post_status = 'publish'
That works as expected in MySQL (returning the count of published posts with the “Author” custom field), but the following returns the string “Array” in the Page template:
$numpostss = $wpdb->get_results("SELECT COUNT(*) FROM $wpdb->postmeta wpostmeta, $wpdb->posts wposts WHERE wpostmeta.meta_key = 'Author' AND wposts.ID = wpostmeta.post_id AND wposts.post_status = 'publish'", ARRAY_N); echo $numposts = $numpostss[0];
Forum: Fixing WordPress
In reply to: how to page custom database query (to sort by custom field)?Thanks for the feedback.
All of the code I’ve shown is in the Page template. Other variables, but not $numpages, seem to be usable throughout the template script (in fact, for now, I’m just recalculating $numpages at the bottom of the page from those other variables).
The question I had about using LIMIT in the query is knowing when I’m on the last page, which would usually be when the number of posts is less than the $postsperpage — but what if it’s equal to that number but it’s the last page? So I’d still want to do a query to find out how many posts there are in total. And I’d want to be able to know how many pages there are in total so I can have a navigation link for each page on all of the pages.
I’ll re-do this with an initial query to count the number of posts with “Author” metadata, which I guess would be much faster each time than getting all of the posts.
(By the way, this is not a blog with tens of thousands of posts, but more a CMS-type reference library — after more than 2 years, there are only just over 360 posts.)
Forum: Fixing WordPress
In reply to: how to page custom database query (to sort by custom field)?I’ve run into a problem farther down the page, now.
The following is an attempt to create prev/next navigation right after the end of the loop above.
<?php $precpage=$paged-1; $nextpage=$paged+1; if ($paged>1) { if ($precpage==1) { echo ('<a href="../../">« Home</a>'); } else { echo ('<a href="../' . $precpage . '/">« Preceding Page</a> • <a href="../../">Home</a>'); } } if ($paged<$numpages) { if ($paged==1) { echo (' • <a href="./page/'); } else { echo (' • <a href="../'); } echo ($nextpage . '/">Next Page »</a>'); } ?>
The “home” link is provided only if it’s not page 1, and the “preceding” link only if it’s page 3 or more. The “next” link is provided as long as the current page is less than the total number of pages (as determined earlier).
That “next” link isn’t working, though, because the value for $numpages has apparently changed to 1. (If I remove the “if($paged<$numpages)” condition, the link is created — but the last page would then point to a nonexisting page.)
What happened to $numpages?
Forum: Fixing WordPress
In reply to: how to page custom database query (to sort by custom field)?This is working:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $postsperpage = 30; $pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'Author' AND wposts.post_status = 'publish' ORDER BY wpostmeta.meta_value ASC", OBJECT); $numposts = count($pageposts); $numpages = $numposts/$postsperpage; if ($numposts%$postsperpage) $numpages=$numpages+1; ?> (navigation stuff) <?php if ($pageposts): $i=$postsperpage*($paged-1); while ($i<$postsperpage*$paged): $post=$pageposts[$i]; setup_postdata($post); ?> (loop stuff) <?php $i++; endwhile; endif; ?>