petra5
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: WordPress SEO (Yoast) add itemprop="description" to meta descriptionI looked into class WPSEO_Frontend into a bit more details and we have function metadesc with an option not to echo the description. Here is top of the function:
/** * Outputs the meta description element or returns the description text. * * @param bool $echo Whether or not to echo the description. * * @return string */ public function metadesc( $echo = true ) { if ( get_query_var( 'paged' ) && get_query_var( 'paged' ) > 1 ) return;
I tried adding the following code in the function above, but it still doesn’t work:
$metadesc = $wpseo_front->metadesc( $echo = false );
Any ideas anybody how to make this work?
Forum: Fixing WordPress
In reply to: WordPress SEO (Yoast) add itemprop="description" to meta descriptionYes, I would like to implement itemprop=”description” so that we have better chances in appearing in in-depth articles search results. See the following from Google:
https://support.google.com/webmasters/answer/3280182?hl=enForum: Fixing WordPress
In reply to: WordPress SEO (Yoast) add itemprop="description" to meta descriptionThank you ELExG for your reply. Yes, I guess that’s one option, but I would rather not mess with plugin files as everything would get overridden with the update.
Forum: Fixing WordPress
In reply to: get list of subcategories(links) with relevant postsOk I’ve been trying different things, but no success just yet.
I have a list of subcategories in a sidebar and I also get a list of posts underneath each category. I only want to show those posts when we are under that subcategory or when we are viewing one of the posts. Each post comes under top level category and subcategory and I don’t know how to get current subcategory id/name. I understand you get a category ID like this: $category = get_the_category();
$catID = $category[0]->cat_ID;
but what about when a post belongs to subcategory and category?
Anyone?
the loop to show the posts:<?php if ((in_category($thiscat)) || (is_category($thiscat))) { ?> <ul class="children"> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php /*general loop output; for instance: */ ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul>
Forum: Fixing WordPress
In reply to: While creating a custom category templateI can’t see a reason why it works only for parent 5.
Forum: Fixing WordPress
In reply to: get list of subcategories(links) with relevant postsI currently have this loop to display posts:
<ul class="children"> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul>
Forum: Fixing WordPress
In reply to: get list of subcategories(links) with relevant postsOk, I figured out how to get the categories links:
foreach ($cats as $cat) : $args = array( 'category__in' => array($cat->term_id) ); $my_query = new WP_Query($args); if ($my_query->have_posts()) : ?> <li><a href="<?php echo get_category_link($cat); ?>"><?php echo $cat->name; ?></a></li>
Thanks alchymyth for pointing me in the right direction.
Now I just need to figure out how to display a list of posts under certain subcategory only when viewing that category. Any ideas where to start?Forum: Fixing WordPress
In reply to: get list of subcategories(links) with relevant postsHow do I get a category id of a sub category in a loop?
beginning of my code:<?php $cats = get_categories('child_of=6'); foreach ($cats as $cat) : $args = array( 'category__in' => array($cat->term_id) ); $my_query = new WP_Query($args); if ($my_query->have_posts()) : ?>
Forum: Fixing WordPress
In reply to: get list of subcategories(links) with relevant postsI tried this:
<?php $category_id = $category->term_id; ?> <li><a href="<?php echo get_category_link($category_id); ?>"><?php echo $cat->name; ?></a></li>
but it is giving me a link to a top category (category 6) instead of relevant subcategory.
Forum: Fixing WordPress
In reply to: get list of subcategories(links) with relevant postsmy code is here:
https://pastebin.com/UTP8add5Forum: Fixing WordPress
In reply to: While creating a custom category templateForum: Fixing WordPress
In reply to: While creating a custom category templateactually I think you need to check if is subcategory of 4, so you would put a function in functions.php:
function is_subcategory (){ $cat = get_query_var('cat'); $category = get_category($cat); $category->parent; return ( $category->parent == '0' ) ? false : true; }
and then do this:
if (is_category(4)) || (is_subcategory(4))Forum: Fixing WordPress
In reply to: While creating a custom category templatetry:
if ((is_category(4)) || ($post->parent == 4))Why it It will never work with
$query = new WP_query($args)?I am using new WP_query for this
Forum: Fixing WordPress
In reply to: wp_query and post_parent -> not workingok, I tried and it works! Thanks so much for this!