I'm looking for a WordPress way to remove current and all grandparents from breadcrumbs. Basically, functionality is identical to history back button, but with page title. Don't want to do this in JS for obvious reasons.
Any ideas?
Cheers!
There is an easy solution to that, no need for breadcrumbs:
<?php if($post->post_parent) {
$parent_link = get_permalink($post->post_parent); ?>
Back to <?php echo get_the_title(wp_get_post_parent_id( $post_ID )); ?>
<?php }
Related
I want to show home page title in breadcrumb. I have tried the get_the_title() function, but it requires page id as parameter. I believe it will break when I change the front page to other page.
Is there a function that is more change prone?
this is how I solved my problem
$home_title = get_the_title( get_option('page_on_front') );
that way, when I change home page with diferent page, the code won't break. It also works on multisite.
Please try this..
<?php echo bloginfo('title'); ?>
<?php echo bloginfo('title'); ?>
This will echo you title of your website given in settings.
Just came across an issue with my Wordpress template that I can't figure out. I am using a custom built menu (done simply with a quick query_posts() call), but when searching for certain terms, my query is affected. Not a clue as to why.
Here's my menu code:
<?php $main_cats=explode(",",$options['main_cats']); ?>
<?php $myargs = array('post_type' => 'page', 'post__in'=>$main_cats,'order'=>'ASC'); ?>
<?php query_posts($myargs);
while ( have_posts() ) : the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; wp_reset_query();?>
This should end up with 4 menu items. However, when searching for a few "job" related items, it seems that the Job Manager plugin steps in (http://pento.net/projects/wordpress-job-manager-plugin/) and I get one menu result stating "This job doesn't exist". However, I don't understand how that plugin could possible affect my query.
Any thoughts?
This code assume that $main_cats has the right data, before testing this, check that the variable is correct:
<?php
$main_cats=explode(",",$options['main_cats']);
$menu_items=get_posts(array('post_type' => 'page', 'post__in'=>$main_cats,'order'=>'ASC'));
foreach($menu_items as $menu_item){ ?>
<li><?php echo $menu_item->post_title; ?></li>
<?php } ?>
Maybe Use native menu function to to create menu's, http://codex.wordpress.org/Function_Reference/wp_nav_menu
Don't use query_posts($myargs), query_posts() is meant for altering the main loop.
Use WP QUERY http://codex.wordpress.org/Class_Reference/WP_Query (or get_posts).
Try wp_reset_query(); before your query as well as after, like you have. I think that the plugin query is happening before your yours. There may be some carry over from that. Reseting before your query might give you a clean slate.
Having a bit of an issue with Wordpress here. In all honesty I've always designed my sites from scratch and "coded" from the ground up. Lately I've been trying to work with WP as I've heard good things about it.
It would appear that WP gives you many things for free (e.g. dynamic "pages" based on CATEGORIES). However, I would like to know how to manipulate these freebies without reinventing the wheel. For example, I would like to have my SUB-MENU display a list of post categories. But I would like to sort those categories by a CUSTOM FIELD.
Now, I could reinvent the wheel and manually create (and link to) a new page for each sort, so on and so forth, (which I don't fundamentally mind doing) however, I'm hoping there is a way around this via plugins or otherwise. I've seen several tutorials on custom queries, but they stop short of implementation -- they simply give the query without telling exactly whether to create a new page or plug it into a function somewhere.
Any input would be most appreciated.
Best.
At the top of category.php template in your theme's root directory, add the following to add your custom sort field to the query:
<?php
function is_valid_custom_sort_field($field)
{
// implementation left as an exercise for the questioner
return true;
}
if ($_REQUEST['sort_custom_field'] && is_valid_custom_sort_field($_REQUEST['sort_custom_field'])) {
query_posts($query_string . '&orderby='.$_REQUEST['sort_custom_field']);
}
See:
http://codex.wordpress.org/Function_Reference/query_posts
If your theme doesn't have a category.php, here is a simple default template to base it on (copied from the included twentyten theme):
<?php
/**
* The template for displaying Category Archive pages.
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
<h1 class="page-title"><?php
printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' );
?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';
/* Run the loop for the category page to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-category.php and that will be used instead.
*/
get_template_part( 'loop', 'category' );
?>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I'm using the Drupal views module to create an overview of nodes. In the view i created i configured the Title. But now when the page is rendered the title isn't shown. It is shown in the breadcrumb etc. But not in the grid template, also if i use another template it still doesn't show. Any idea what this can be? I tried looking for it, but my experience with Drupal is very limited.
I checked the drupal_get_title etc. and it is always returning the title, i think something goes wrong in the views module, but i don't know what :s
Kind regards,
Daan
The problem is most likely how you print the page title. If you want it to happen globally, you should print it in the page.tpl.php. Have you inspected the $title variable in the page template? That is what it's usually called.
i idd removed the title from page.tpl.php, but i did this because i thought it should be printed in the views template. When you check views-view-unformatted.tpl.php etc you see this:
<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
<div class="<?php print $classes[$id]; ?>">
<?php print $row; ?>
</div>
<?php endforeach; ?>
so i thought $title would print the title, but it is fixed just by adding it in my page.tpl.php
I am trying to pull in a styled sidebar specific to the category. I have the following code which works, but it is pulling in BOTH my new sidebar and the default. What am I doing wrong here?
From category.php
<?php get_sidebar();
if ( in_category('39') ) {
include(TEMPLATEPATH . '/sidebar2.php');
} else {
include(TEMPLATEPATH . '/sidebar.php');
}
?>
<?php get_footer(); ?>
Because you're calling sidebar twice; do this:
<?php
if ( in_category('39') ) {
include(TEMPLATEPATH . '/sidebar2.php');
} else {
include(TEMPLATEPATH . '/sidebar.php');
}
?>
There is a slight problem with the code being provided to you. But as Eimantas suggested, you could simply make a new file called category-39.php which will accomplish the job perfectly, if though for some reason you are still wanting to continue using your category.php file, then here is what you would need to do:
if ( is_category('39') ) {
get_sidebar('2');
} else {
get_sidebar();
}
?>
<?php get_footer(); ?>
The difference between this and the code that you posted is that I have removed
<?php get_sidebar(); ?>
Additionally I have changed in_category to is_category. The reason for this is because when looking at the category page itself using is_category will change on the category list, whereas in_category only looks at the current post and therefore will not change according except when looking at the single.php page.
Example:
in_category will change the sidebar for the following url www.mysite.com/category/stuff/myfirstpost
But it will not change the sidebar for this url www.mysite.com/category/stuff
Simply using is_category will fix this problem.
The next thing would be using
get_sidebar('2');
and
get_sidebar();
get_sidebar(); will run the appropriate wordpress functions related to the sidebar in addition to including sidebar.php.
get_sidebar('2'); on the other hand will run all the appropriate wordpresss functions related to the sidebar while also loading sidebar-2.php.
Hope this helps,
Remove this from your code:
get_sidebar();
otherwise you call this file "sidebar.php" twice...
if you look into wp documentation http://codex.wordpress.org/Function_Reference/get_sidebar
you can do it like that:
<?php
if ( in_category('39') ) :
get_sidebar('two'); //this will include sidebar-two.php
else :
get_sidebar();
endif;
?>
You should create separate template named category-39.php and do common design stuff. WP itself will notice that it should apply this template to category with id=39. No need for if else statements.