Nessdufrat
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Counting characters for all the postsHi!
I found the solution. Actually, WordPress puts posts and pages in the same table.
Here’s the code :<? global $wpdb; $total_charcount = 0; // Get all the posts $result = $wpdb->get_results("SELECT post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'", OBJECT); foreach($result as $post) { $total_charcount = $total_charcount + strlen(strip_tags($post->post_content)); } echo '<p>Characters spaces included :' .$total_charcount. '</p>'; ?>
Forum: Fixing WordPress
In reply to: Conditional statement including category AND child-categoriesOh, thanks ?? That might come in handy too ??
Forum: Fixing WordPress
In reply to: Conditional statement including category AND child-categoriesOh, yeah, that’s exactly what I wanted right from the beginning ^^ Thanks a lot ??
So, actually, what was different with the code you wrote (is_category_tree) ? Does the function allows other things than this piece of code doesn’t?
(you’ve been a huge help, BTW, thanks!!!)Forum: Fixing WordPress
In reply to: Conditional statement including category AND child-categoriesQuestion, once more (sorry). I’m trying to clean up the code a little and I like switch statements.
I’ve been trying to implement it, but it doesn’t work, I’m not sure if I can do a switch on $branch, or if can simply call the function… I tried a bunch of solutions, but none worked :<h1 class="page-title <?php function is_category_tree($branch='') { $cat = get_term_by('name',$branch,'category'); if( !$cat ) $cat = get_term_by('slug',$branch,'category'); if( !$cat ) $cat = get_term_by('id',(int)$branch,'category'); $this_cat = get_query_var('cat'); if( $cat && is_category() && ( $cat->term_id == $this_cat || in_array( $cat->term_id, get_ancestors( $this_cat, 'category' ) ) ) ) return true; else return false; } switch (is_category_tree($branch)) { case 3: echo 'edition'; break; case 4: echo 'autopublication'; break; case 2: echo ""; break; }?>">
Forum: Fixing WordPress
In reply to: How to call a page in a widget ?Oh, thanks, that’s exactly what I was looking for ??
Forum: Fixing WordPress
In reply to: How to call a page in a widget ?Yeah, I found it a while after posting my question. I’d prefer a wordpress function, but I guess I can try to take appart the plugin and pick up only what I need ?? It’s designed to be permanent, so I don’t need the functionalities of a widget.
Actually, one of the reasons I don’t like widgets is because they show up as “primary” “secondary”, etc. as ids, and it makes it difficult to have something clear ^^Forum: Fixing WordPress
In reply to: Conditional statement including category AND child-categoriesOh my… thanks. Does it show I’ve slept like 4 hours this night ? :/
Thanks a lot !!!Forum: Fixing WordPress
In reply to: Conditional statement including category AND child-categorieshttps://www.espacescomprises.com
Here is my category template : https://pastebin.com/sHnQYj2VAnd the functions.php doc : https://pastebin.com/1iwknNGV
(I tried first to put the function you wrote in my category template, but as it didn’t work, I put it in functions.php. Doesn’t work better, though)
I can’t really let the website with the error on it because I need to work on it and I can’t do that if I don’t see what I’m doing, so I’ll leave it like that for 20 minutes, then I’ll change it back to something that works.
Just in case, here’s the error : Parse error: syntax error, unexpected $end in /homez.490/espacesc/www/wp-content/themes/espacescomprises/category.php on line 41Forum: Fixing WordPress
In reply to: Conditional statement including category AND child-categoriesOk, so no idea why, but yesterday it was working, and now, I get “édition” no matter what category it is…
A friend has been working on the website too, adding categories, but she didn’t touch the code or the existing category names. I double-checked the ID, they are still the same.
The matter appears to be with get_categories(‘child_of=id’). When I get rid of this, it’s fine. But I need to have the child categories having the same styling as the parent ??alchymyth, I tried your code, and it’s conflicting with wordpress code, I think. I’m getting an error after the get_footer(); part, like unexpected $end or something.
I checked all the brackets, they are correct.Forum: Fixing WordPress
In reply to: Conditional statement including category AND child-categoriesOk, thanks ! I might try that !
I was thinking of keeping my conditional but making it cleaner using switch, like :<?php switch(id) { default: echo "whatever"; break; case 4: echo "stuff for cat id 4"; break; case 3: echo "stuff for cat id 3"; break; } ?>
I haven’t been programming anything in php for 4 years, so I’m a bit rusty.
What I could use for id could be your ‘cat’ variable? Or is there a more direct way to do it with my switch structure?
Can I do something like :
switch(is_category($id) || get_categories(‘child_of=$id’)) ?Forum: Fixing WordPress
In reply to: Conditional statement including category AND child-categories^^ My brain works in a stupid way, most of the time, when I ask a question, I find the answer by myself a few minutes later even if I had been looking for it for two hours. I guess trying to explain it to somebody else does the trick ??
I might try to clean up the code a little, right now it’s a bit ugly ??Forum: Fixing WordPress
In reply to: Conditional statement including category AND child-categoriesRahhh, stupid me, it was so simple…
So, here it is, if somebody is looking for a solution :
<h1 class="page-title <?php if (is_category('édition') || get_categories('child_of=4')) : echo 'edition'; elseif (is_category('Auto-publication') || get_categories('child_of=3')) : echo 'autopublication'; else : echo 'categorytitle'; endif; ?>"> <? echo single_cat_title( '', false ) ; ?></h1>
Forum: Themes and Templates
In reply to: AJAX loop to show more posts as user scrolls down the pageOk, never mind, it works. It was a stupid access-control-origin issue… I hate myself for not looking at the console right away…
I found another tutorial and tried to follow it, but it wouldn’t work. Same thing as before, the script part does nothing…
Is there something to activate in order to use AJAX with WordPress?I found something to start with here : https://wordpress.stackexchange.com/questions/35849/using-ajax-on-categories-and-wordpress-loops
But I can’t get it to work. The category list displays fine (no surprise here since it’s a basic wordpress function), but the script part does nothing and I don’t get any post list…
I can’t find out what’s wrong with the code, as I’m not used to ajax stuff…