wordpress url structure - wordpress

Is it possible in wordpress when I call example.com/category to have listed all available categories. If I request the url like in my example I'm getting an 404 page

I'm not sure if there is a default link to list all the categories.
But it doesn't mean you can't do it yourself. Create a new template file in your theme, name it for example category_list.php and add this code:
You might want to tweak it a bit to display it how you want.
<?php
/**
* Template Name: Category listing
* Description: list all the categories
*/
get_header(); ?>
<div class="container">
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($args);
foreach($categories as $category):
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>';
echo '<hr />';
endforeach;
?>
</div>
<?php get_footer(); ?>
Then go to Pages -> add new. Name the Page as "Category", so that the url will be example.com/category.
And in the template list select the template you just created. It will be named "Category listing" as you can see in the code above in the comments at the top.

Related

woocommerce order details dashboard custom text

I am currently using this to add extra information on the order page details. it is working perfect however i want to move it to be under the box where u add notes to customers.
Want the "fast responses" to be under the add note box ( as seen on the picture ), so i can just copy the responses fast when i need them to send to customers. either like that or in a box under it. but i cant find any hooks to talk to the order notes, or after order notes.
// display the extra data in the order admin panel
function kia_display_order_data_in_admin( $order ){ ?>
<div class="order_data_column">
<h4><?php _e( 'Fast responses' ); ?></h4>
<?php
echo '<p><strong>' . __( '2 parcel shippment' ) . ':</strong>' . get_post_meta( $order->id, '_some_field', true ) . '</p>';
echo '<p><strong>' . __( 'You incorrect adress' ) . ':</strong>' . get_post_meta( $order->id, '_another_field', true ) . '</p>';
echo '<p><strong>' . __( 'Your payment failed' ) . ':</strong>' . get_post_meta( $order->id, '_another_field', true ) . '</p>'; ?>
</div>
<?php }
add_action( 'woocommerce_admin_order_data_after_order_details', 'kia_display_order_data_in_admin' );
You can add a meta box under the order notes then print your response in it.
try out this code.
// Adding Meta container admin shop_order pages
add_action('add_meta_boxes', 'zillion_add_meta_boxes');
if (!function_exists('zillion_add_meta_boxes')) {
function zillion_add_meta_boxes()
{
add_meta_box('zillion_other_fields', __('My Response', 'woocommerce'), 'zillion_add_other_fields_for_packaging', 'shop_order', 'side', 'core');
}
}
// Adding Meta field in the meta container admin shop_order pages
if (!function_exists('zillion_add_other_fields_for_packaging')) {
function zillion_add_other_fields_for_packaging()
{
global $post;
?>
<div class="order_data_column">
<h4><?php _e('Fast responses'); ?></h4>
<?php
echo '<p><strong>' . __('2 parcel shippment') . ':</strong>' . get_post_meta($post->id, '_some_field', true) . '</p>';
echo '<p><strong>' . __('You incorrect adress') . ':</strong>' . get_post_meta($post->id, '_another_field', true) . '</p>';
echo '<p><strong>' . __('Your payment failed') . ':</strong>' . get_post_meta($post->id, '_another_field', true) . '</p>'; ?>
</div>
<?php
}
}

Page with category list with image (ACF)

I try to create list of child category with images thumbs.
I add new field to taxonomy (ACF plugin) “image_category” and now I try to add this image to the list:
<?php
$args = array('parent' => 3);
$categories = get_categories( $args );
$term = get_queried_object();
$image_category = get_field('image_category', $term);
foreach($categories as $category) {
echo '<div class="col-md-3 col-sm-12 col-xs-12 text-center pb-3"><img src="' . $image_category . '"><h3><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </h3> ';
echo '<p> <strong>Number post:</strong> '. $category->count . '</p></div>';
}
?>
I see category list, name, number post. Only image dont work.
Image link dont show. I have on consol only “img src=(unknown)”. What am I doing wrong?

Wordpress with Genesis framework, how do I change the output of an archive page for a custom content type?

I have an archive page for a custom content type, and I want to display one of the custom fields in the archive listing. Im not sure what hook to use or how to access the variables in the custom content type to display in -archive.php. Can anyone help me out with the relevant hooks, or how to access those field variables?
First create archive file with your custom post type, the file name should be like this archive-{post_type}.php
Go through the below code this may help you
<?php
remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
add_action( 'genesis_loop', 'custom_do_grid_loop' ); // Add custom loop
function custom_do_grid_loop() {
// Intro Text (from page content)
echo '<div class="page hentry entry">';
echo '<h1 class="entry-title">'. get_the_title() .'</h1>';
echo '<div class="entry-content">' . get_the_content() ;
$args = array(
'post_type' => 'custom post type', // enter your custom post type
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page'=> '12', // overrides posts per page in theme settings
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ):
while( $loop->have_posts() ): $loop->the_post(); global $post;
echo '<div id="testimonials">';
echo '<div class="one-fourth first">';
echo '<div class="quote-obtuse"><div class="pic">'. get_the_post_thumbnail( $id, array(150,150) ).'</div></div>';
echo '<div style="margin-top:20px;line-height:20px;text-align:right;"><cite>'.genesis_get_custom_field( '_cd_client_name' ).'</cite><br />'.genesis_get_custom_field( '_cd_client_title' ).'</div>';
echo '</div>';
echo '<div class="three-fourths" style="border-bottom:1px solid #DDD;">';
echo '<h3>' . get_the_title() . '</h3>';
echo '<blockquote><p>' . get_the_content() . '</p></blockquote>';
echo '</div>';
echo '</div>';
endwhile;
endif;
echo '</div><!-- end .entry-content -->';
echo '</div><!-- end .page .hentry .entry -->';
}
/** Remove Post Info */
remove_action('genesis_before_post_content','genesis_post_info');
remove_action('genesis_after_post_content','genesis_post_meta');
genesis();
?>

Creating a recent posts widget for wordpress but ran into problems where it displays info from the first post

Hey guys I am making a Widget to display a posts title, and excerpt from that post, and its date. The code I have is here:
public function widget( $args, $instance ) {
extract( $args );
$headline = $instance['headline'];
$category = $instance['category'];
$numberposts = $instance['numberposts'];
$readmore = $instance['readmore'];
echo $before_widget;
echo $before_title;
echo "<p class=\"headline\">$headline</p>";
echo $after_title;
$args = array( 'numberposts' => $numberposts, 'category_name' => $category );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<a href="' . get_permalink($recent["ID"]) . '" title=" '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> ';
echo the_time('F j, Y');
echo the_excerpt();
}
As you can see I am trying to call the time and the excerpt from the post. It is working but it is only displaying the date and and excerpt from the very first post that is called welcome. I want it to display the Date and excerpt from each individual post. I will post a link to the site with the widget in the side bar. Sorry if I am not being clear enough or if more info is needed I am very new to this.
http://www.modmacro.us/wpsandbox/
First thing: the_excerpt(), is already an echo statement. Not a return statement. It's the same with the_date(). Prefix them with "get_", and they will return the information you need, or you can get rid of the echo command preceding it.
Second thing: In order for those functions to work, they need to be used in a Wordpress loop.
Since we're already in a loop, we just have to make sure it changes the Wordpress Globals appropriately to reflect the information you need..
foreach( $recent_posts as $recent ){
setup_postdata(get_post($recent['ID']));
echo '<a href="' . get_permalink() . '" title=" '.esc_attr(get_the_title()).'" >' . get_the_title().'</a> ';
echo get_the_time('F j, Y', $recent['ID']);
the_excerpt();
}
wp_reset_postdata();

wordpress recent categories widget

I have used the following code to display the recent categories <?php wp_list_categories( 'title_li=<h3>' . __('Recent Categories') . '</h3>' ); ?>. I need to exclude some categories from display. How can i do that?
You might try using 'get_categories' instead. It's a bit more complicated, but a lot more flexible. You can exclude specific cats with this function by including a comma-separated list of categories in the args. See below:
$args=array(
'orderby' => 'name',
'order' => 'ASC',
'exclude' => '1,4,9' <--- Add your cats to exclude here
);
$categories=get_categories($args);
foreach($categories as $category) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>';
}
Read more about get_categories at http://codex.wordpress.org/Function_Reference/get_categories
?>

Resources