Michael
  • Member for 10 years, 9 months
  • Last seen this week
  • Canada
How to determine if I'm on the first page of pagination?
38 votes

if you only want to know that you're on the first page of a paginated page try is_paged(): if ( !is_paged() ) { // first page of pagination }

View answer
How to display related posts from same category?
Accepted answer
28 votes

One possibility: $related = get_posts( array( 'category__in' => wp_get_post_categories( $post->ID ), 'numberposts' => 5, 'post__not_in' => array( $post-&...

View answer
is it possible to get next_post_link
Accepted answer
20 votes

try to work with http://codex.wordpress.org/Function_Reference/get_adjacent_post; example: $next_post_link_url = get_permalink( get_adjacent_post(false,'',false)->ID ); $prev_post_link_url = ...

View answer
Insert image or ad script after 3 posts using the loop
Accepted answer
16 votes

instead of a post counter, you could use the variable $wp_query->current_post - which starts with 0 for the first post in the loop; for some output after the third post, use for instance this ...

View answer
Get featured image on Blog Index
Accepted answer
15 votes

if you are referring to the 'page for posts', then try (only relevant section of your code shown): if (is_home() && get_option('page_for_posts') ) { $img = wp_get_attachment_image_src(...

View answer
get_categories hierarchical order like wp_list_categories - with name, slug & link to edit cat
Accepted answer
13 votes

output as unordered list: <?php hierarchical_category_tree( 0 ); // the function call; 0 for all categories; or cat ID function hierarchical_category_tree( $cat ) { // wpse-41548 // ...

View answer
Wrap Post count in a span
Accepted answer
13 votes

adding a filter to functions.php of your theme is one possibility: add_filter('wp_list_categories', 'cat_count_span'); function cat_count_span($links) { $links = str_replace('</a> (', '</a&...

View answer
exclude category from get_posts?
Accepted answer
12 votes

as 'get_posts()' uses the 'WP_Query()' parameters, i would assume that this should work: $laargsM = array( 'cat' => 7, 'posts_per_page' => 300, 'orderby' =&...

View answer
How can I add comments to a page?
Accepted answer
10 votes

Have you checked under Admin -> Settings -> Discussion and for individual pages, under pages and quick-edit or the discussion area in edit page below the page editor? When the last one does not show,...

View answer
What filters are applied to the_content function?
Accepted answer
8 votes

the default filters are set in /wp-includes/default-filters.php; for 'the_content' this is from line 135: add_filter( 'the_content', 'wptexturize' ); add_filter( 'the_content', '...

View answer
Show content only on front page?
8 votes

<?php if(is_home() && !is_paged()) { ?> http://codex.wordpress.org/Conditional_Tags

View answer
Wordpress WP_Query() Not working properly
8 votes

a possible conflict with the name $posts which is used by wp core; try, for instance: $categories = get_categories(); foreach($categories as $category) { printf('<h2>%s</h2><...

View answer
How can I get the content of the home page?
7 votes

alternative to using the default loop in the front-page.php template: if( have_posts() ) { while( have_posts() ) { the_post(); the_content(); } } you could try using: if( get_option( '...

View answer
ID for posts/blogs page
Accepted answer
7 votes

consider to use: $postspage_id = get_option('page_for_posts'); and then change the rspective line in your code to: $leftSidebar = get_post_meta( $postspage_id, '_my_meta', true ); from: http://...

View answer
How to translate month names in "Archives"
Accepted answer
7 votes

if the translation is only for the archive widget, a filter function might work (to be added to functions.php of the theme): add_filter('get_archives_link', 'translate_archive_month'); function ...

View answer
page title, parent tilte and grand parent title
Accepted answer
6 votes

possibly build on get_ancestors(); example: if( is_page() ) : echo $post->post_title; if( $ancs = get_ancestors($post->ID,'page') ) { foreach( $ancs as $anc ) { echo ' -...

View answer
How to make the first post in the loop be styled like a "new / featured" post?
Accepted answer
6 votes

one loop with a conditional statement to catch the first post should work; example: <?php if( $wp_query->current_post == 0 && !is_paged() ) : ?> /*the output of the first post*? <?...

View answer
How to get the number of Pages in a single Post Pagination?
5 votes

have a look at https://codex.wordpress.org/Global_Variables#Inside_the_Loop_variables within the loop, the global variables related to the <!--nextpage--> tag are: $page - the actual sub page, ...

View answer
Multiple loops in same page, without duplicate content
Accepted answer
5 votes

it is important to read this Codex chapter all the way to the end, as the essential suggestions are after this heading 'Note for Multiple Posts in the First Category'; repetitive, tedious code: <?...

View answer
Optimal approach for replacing the 8 header images in a child theme?
Accepted answer
5 votes

I am never sure about 'optimal approach' - however, I am using this in the functions.php in a child theme of Twenty Eleven //deregister the header images of Twenty Eleven, and register a few new RAW ...

View answer
How do I change the output of get_the_tag_list()?
5 votes

you could use a filter function, added to functions.php of your theme: add_filter('the_tags', 'wp32234_add_span_get_the_tag_list'); function wp32234_add_span_get_the_tag_list($list) { $list = ...

View answer
How do you change the visual editor's background color?
Accepted answer
5 votes

similar to the answer by GavinR, using the wordpress add_editor_style() function; (as implemented in Twenty Ten and Twenty Eleven) in functions.php of your theme, add: add_editor_style(); then ...

View answer
Getting an ordered list of tags - via wp_tag_cloud or not?
Accepted answer
5 votes

one possibility: using the 'format=array' and 'echo=0' parameters; and building a foreach loop to output each tag: <ol> <?php $wptc = wp_tag_cloud('smallest=12&largest=12&...

View answer
In need of array of post tags
Accepted answer
4 votes

the function get_the_tags() does for a single post, what get_tags() does for the site.

View answer
Link to blog index from template
Accepted answer
4 votes

if you are referring to the 'posts page' as set under dashboard - settings - reading: <?php if( get_option( 'page_for_posts' ) ) { echo get_permalink( get_option( 'page_for_posts' ) ); } else ...

View answer
add_filter on "the_excerpt" only works when post does not have excerpt
Accepted answer
4 votes

I posted an article about this a while ago: function wp_trim_all_excerpt($text) { // Creates an excerpt if needed; and shortens the manual excerpt as well global $post; $raw_excerpt = $text; if ...

View answer
Remove Content after <!--more-> tags
Accepted answer
4 votes

set the $stripteaser parameter to true; the_content('readmore', true); http://codex.wordpress.org/Function_Reference/the_content

View answer
How can I have a static title on my blog page?
4 votes

the accepted answer in the similar question on stackexchange should work; try to add this to a suitable location in index.php of your theme: <?php if( is_home() && get_option( '...

View answer
Automatic excerpts
Accepted answer
4 votes

general: locate the template for the home page - often index.php - if not see http://codex.wordpress.org/Template_Hierarchy find the_content() (possibly with some parameters in the brackets) and ...

View answer
Add an extra field to the navigation menu box?
Accepted answer
4 votes

have you ticked the 'Description' box under 'Show advanced menu properties' in the 'screen options' tab in the appearance -> menus page? and have a look at this related post: http://www.kriesi.at/...

View answer
1
2 3 4 5
10