I want to display the linklist widget only on a certain category.
The current way the sidebar is fetched is:
if (!function_exists('dynamic_sidebar') || !dynamic_sidebar(1))
Which doesnt give me a say in the calling of the links widget. If i put an if clause there, then the rest of the widgets dont get loaded.
So i either need to customize the links widget it self or find a way to call the links widget directly?
And how do i check which category i'm on?
You can call an indivdual widget by using Conditional Tags « WordPress Codex, like this:
<?php if (in_category('1')) { ?> call widget here
<?php } ?>
Or (haven't used this myself) load widgets by category, etc: WordPress › Dynamic Widgets « WordPress Plugins
To print the Category you are on use the_category(' ');
Example :<p>Categories: <?php the_category(' '); ?></p>
Also have a look at the Documentation http://codex.wordpress.org/Template_Tags/the_category
Related
In my current WordPress theme, i have some 5 widgets.
I tried with plugins available on internet but that not solved my problem.
I want to use more widgets in my theme in single sidebar.
How can i add more widgets in WP theme?
Thanks
Most widgets give you a shortcode to put into one of the pages that wil be echoed out through the the_content(); function.
So if you would like to process those shortcodes in the PHP to make them in custom places would probably be your best bet.
You can do that like this:
<?php echo do_shortcode( $content ) ?>
Here is the reference
I am building an artist directory page which displays all the artist pages as thumbnails with captions.
I would then like it so that when you click on one of the thumbnails it takes you to that page and shows the various fields ACF.
However, it only shows the title and I cannot get it to display the bio field at all!
<h1><?php echo $post->post_title; ?></h1>
<div id="artist-bio">
<?php the_field('artist_bio'); ?>
</div>
first, it's a good practice to check if your fields have been set in the first place. You can test like this:
if (get_field('artist_bio') {
the_field('artist_bio');
} else {
echo "Artist bio has not been set";
}
If it's claiming that it hasn't been set, yet you're sure it is, then there's probably an issue with the loop. Are you inside the default loop, or are you running a custom query? In the latter case you would need to modify your command like so: the_field('artist_bio', $post->ID).
I want to display different dynamic sidebar on different pages, how do I access multiple sidebar on my pages.
Place some form of hook on different pages.
Open sidebar.php in your themes and check for presence of hook.
You should create files like sidebar-xxxx.php and include it, using get_sidebar(xxxx) in the different templates and souhld register them on the functions.php. If you do not wanna create these files you can register the sidebars on functions.php and in the sidebar.php use:
global $wp_query;
$page_name = $wp_query->post->post_name;
<ul>
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-'.$page_name) ) : ?>
<?php endif; ?>
</ul>
create a new sidebar
and you can link them inc with is page
if(is_page(5)) {
include('new-sidebar.php')
}
is page id is 5 lets say thats the id for your home page
just check the ids of your pages and seperate them
if you want them tho show in the page childs to
just write
if(is_page(5) || $post->post_parent) {
include('new-sidebar.php')
}
zou can even write a function either
For different sidebars, i thing you have to do is to create the sidebar which you want as many as you want and save those sidebars as sidebar1.php, sidebar2.php and so on.
And,just include it in the different pages where you want it to display like this:
<?php include('sidebar1.php'); ?>
And, like wise for other sidebars of other pages.
I use Barecity Theme for WordPress. i built everything, but now i need to add a single.php file to theme. now it displays all post content at homepage, I created a short_desc Custom Field. and I call it from code with;
<?php //get_post_meta($post->ID, 'short_desc', true); ?>
it is fine. but i need to display this short desc at home page listing, and the main content at details page. how can do that?
I appreciate helps!!
It sounds like what you are trying to do is show a custom field that you have set on a post on the index page (which lists all the posts).
To do that you'll need to modify index.php by adding your snippet where you would like to have the short description.
<?php echo get_post_meta($post->ID, 'short_desc', true); ?>
You need to use echo to display the results from the get_post_meta function.
Depending on how your posts are setup you can also use the More button when you write your posts. This will cut off your post at a certain point that you decide and only show that short part on the index and archive pages.
Another option would be to use
<?php the_excerpt(); ?>
Which shows the first 55 words (this can be adjusted though) of the post.
Hope that helps,
Paul
I am trying to display just post title and their links within a set category. However I am running into issues understanding the Codex. Any help or guidance would be greatly appreciated.
I use this a lot in my blogs. Helpful when you want to display featured items or such.
http://codex.wordpress.org/Template_Tags/query_posts#Category_Parameters
http://codex.wordpress.org/The_Loop#Style_Posts_From_Some_Category_Differently
You might have seen the above link. I'll explain how it works.
Posts are loaded using the loop. If you do a Query Posts just before the loop, you can choose from select category (or many categories) and also limit the number.
<?php query_posts('cat=1&showposts=5'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><?php the_title(); ?>
<?php the_excerpt() ?>
</li>
<?php endwhile; endif; ?>
You can use the above code as many times you wish. Choose the category ID (can be found from the admin) and the number of posts you wish to show.
Comment - if you require additional help.
It seems that you are working on your templates. It basically means that you need to edit correct template and insert the right tags.
Firstly, you need to understand how the template is chosen. WP has special hierarchy for every view. Home page is usually home.php and categories are category.php or category-1.php. If any file is missing, WP simply takes next on the list. Last on the hierarchy list is index.php which is chosen if no other file is found.
[http://codex.wordpress.org/Template_Hierarchy#Category_display][1]
Secondly, look at the template tags. Displaying only title with link means you need title and permalink tag. Anything else is optional.