Jump to content

Coding question in Wordpress


montytx

Recommended Posts

Hi All,

Im new here and not much of a coder so I am hoping someone can help me figure out a simple problem. I have a wordpress site that I want to control what category shows up on the front page. The theme is custom so standard wordpress code is not being used. The code that I think controls this is:

<?php if (Themehave_random_posts()) : ?>
		<?php while (Themehave_random_posts()) : $theme_queryRandom->the_post();
			if(!@in_array(get_the_ID(), $showedPosts)){?>

 

In the functions.php I have this code:

function Themehave_random_posts(){
global $wp_query, $shortname, $theme_queryRandom, $wpdb, $cx, $showedPosts, $ids;
if(!$theme_queryRandom){
$show = (int)get_settings($shortname."_randomCategoryPosts");
if(!in_array($show, $ids))
$ids[] = $show;
$theme_queryRandom = new WP_Query('category_name='.get_cat_name($show).'&orderby=rand&showposts=1');
}
$aux = $theme_queryRandom->have_posts();
if(get_the_ID())
$showedPosts[] = get_the_ID();
return $aux;
}

 

 

Any help is greatly appreciated. Thanks !

Link to comment
https://forums.phpfreaks.com/topic/146122-coding-question-in-wordpress/
Share on other sites

  • 2 weeks later...

no... it's not necessarily complicated, but it's not so easy either. at least it is for me, because i haven't use wordpress.

 

i don't know how this works entirely, but you should try this:

 

function Themehave_random_posts(){
global $wp_query, $shortname, $theme_queryRandom, $wpdb, $cx, $showedPosts, $ids;
if(!$theme_queryRandom){
$show = (int)get_settings($shortname."_randomCategoryPosts");
if(!in_array($show, $ids))
$ids[] = $show;
$catiwant = 'my category'; // put your category in the apostraphies...
$theme_queryRandom = new WP_Query('category_name='.$catiwant.'&orderby=rand&showposts=1');
}
$aux = $theme_queryRandom->have_posts();
if(get_the_ID())
$showedPosts[] = get_the_ID();
return $aux;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.